-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RainMachine switch platform #8827
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good. Some minor comments.
.coveragerc
Outdated
@@ -143,6 +143,9 @@ omit = | |||
homeassistant/components/rachio.py | |||
homeassistant/components/*/rachio.py | |||
|
|||
homeassistant/components/rainmachine.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't add this line since you don't add a component only a platform.
.coveragerc
Outdated
@@ -143,6 +143,9 @@ omit = | |||
homeassistant/components/rachio.py | |||
homeassistant/components/*/rachio.py | |||
|
|||
homeassistant/components/rainmachine.py | |||
homeassistant/components/*/rainmachine.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this with homeassistant/components/switch/rainmachine.py
and move the line to the switch group in alphabetical order.
|
||
|
||
@asyncio.coroutine | ||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this function above the class definitions.
_LOGGER.error('Neither IP address nor email address given') | ||
return False | ||
except rm.exceptions.HTTPError as exec_info: | ||
_LOGGER.error('HTTP error during authentication: %s', str(exec_info)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not have to convert exec_info
into a string. The base Exception
class in Python defines __str__
.
|
||
async_add_devices(entities) | ||
except rm.exceptions.HTTPError as exec_info: | ||
_LOGGER.error('Request failed: %s', str(exec_info)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
|
||
def __init__(self, client, zone_json, **kwargs): | ||
"""Initialize a RainMachine zone.""" | ||
super(RainMachineZone, self).__init__(client, zone_json, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super().__init__(client, zone_json, **kwargs)
except exceptions.HTTPError as exc_info: | ||
_LOGGER.error('Unable to turn off zone "%s"', | ||
self.rainmachine_id) | ||
_LOGGER.debug(str(exc_info)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove str
conversion.
except exceptions.HTTPError as exc_info: | ||
_LOGGER.error('Unable to turn on zone "%s"', | ||
self.rainmachine_id) | ||
_LOGGER.debug(str(exc_info)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
MIN_SCAN_TIME_FORCED = timedelta(milliseconds=100) | ||
|
||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
vol.Optional(CONF_IP_ADDRESS): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Require at least one of the auth keys and make them exclusive, something like this:
PLATFORM_SCHEMA = vol.Schema(vol.All(
cv.has_at_least_one_key(CONF_IP_ADDRESS, CONF_EMAIL),
{
vol.Required(CONF_PLATFORM): cv.string,
vol.Optional(CONF_SCAN_INTERVAL): cv.time_period,
vol.Exclusive(CONF_IP_ADDRESS, 'auth'): cv.string,
vol.Exclusive(CONF_EMAIL, 'auth'): vol.Email,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_ZONE_RUN_TIME, default=DEFAULT_ZONE_RUN_SECONDS): cv.positive_int,
vol.Optional(CONF_HIDE_DISABLED_ENTITIES, default=True): cv.boolean
}
), extra=vol.ALLOW_EXTRA)
Note that you can't extend the platform schema when you want to use a validator around the dict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, but I'm confused on how to utilize it? Without any extra changes, I get exceptions about my ip_address
and email_address
variables (set in async_setup_platform()
) being functions.
Never mind, got it. 😄
_LOGGER.debug('Configuring remote API...') | ||
auth = rm.Authenticator.create_remote(email_address, password) | ||
else: | ||
_LOGGER.error('Neither IP address nor email address given') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add the more extensive platform validation schema you can remove this.
MIN_SCAN_TIME_REMOTE = timedelta(seconds=5) | ||
MIN_SCAN_TIME_FORCED = timedelta(milliseconds=100) | ||
|
||
PLATFORM_SCHEMA = vol.Schema( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redefinition of unused 'PLATFORM_SCHEMA' from line 10
Thanks, @MartinHjelmare – I've made your requested changes. |
I think the branch got jacked. 😜 Edit: Take for habit to work in a separate feature branch of your own, not directly on dev. |
@MartinHjelmare: That's what I had done prior to this PR; not sure what happened. I'll fix shortly. Edit: Alright, we should be in business now (once CI passes). 👍 |
super(RainMachineZone, self).__init__(client, zone_json, **kwargs) | ||
self._run_time = kwargs.get(CONF_ZONE_RUN_TIME) | ||
super().__init__(client, zone_json, **kwargs) | ||
self._run_time = kwargs.get(zone_run_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The argument is already available now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks like what I have. But I think this line should be changed to this:
self._run_time = zone_run_time
Cause zone_run_time
is now available as a positional argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, great point. Updating shortly.
@MartinHjelmare: The lint CI step is failing with this error:
That isn't anywhere in my code; guessing it might be in the platform schema definition. Any advice for me? |
Found this: pylint-dev/pylint#818 – key point:
Going to tell pylint to ignore that issue, then re-push. Holding tight... Edit: Victory! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
* Add RainMachine switch platform * Updated requirements_all.txt * Cleaning up CI and coverage results * Small update to deal with older pylint * Fixed small indentation-based error * Added some more defensive try/except logic around calls * I'm not a fan of importing a library multiple times :) * Making PR-requested changes * Fixed ref to positional parameter * Attempting to fix broken linting * Ignoring no-value-for-parameter pylint error
Description:
Adds support for RainMachine sprinkler controllers (via the Switch component).
Related issue (if applicable):
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#3135
Example entry for
configuration.yaml
(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.