Skip to content
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

Move RainMachine to component/hub model #14085

Merged
merged 10 commits into from
Apr 28, 2018

Conversation

bachya
Copy link
Contributor

@bachya bachya commented Apr 26, 2018

Description:

This is the first of several PRs designed to add more functionality to the RainMachine integration. The first is this, which moves the integration from existing fully in a switch platform to being a combo component + switch platform (a la Arlo, et. al.). No functionality changes, per se, in this PR.

This will be the master PR; fine to merge once it passes tests and review, but others will be held back until this is merged.

BREAKING CHANGE 1: with the migration to the component/hub model, existing configuration files will break. The new format (below) should be used.

BREAKING CHANGE 2: after intense amounts of fiddling, it's clear to me that the RainMachine remote API is broken, clunky, etc. After some investigation, I haven't found a single user who's using it, so using this PR as a time to remove it and references to it.

Related issue (if applicable): N/A

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5251

Example entry for configuration.yaml (if applicable):

rainmachine:
  ip_address: 192.168.1.100
  password: abc123

switch:
  - platform: rainmachine
    zone_run_time: 300

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

from datetime import timedelta

import voluptuous as vol
from requests.exceptions import HTTPError, ConnectTimeout

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'requests.exceptions.HTTPError' imported but unused
'requests.exceptions.ConnectTimeout' imported but unused

_LOGGER.debug('Adding program: %s', program)
entities.append(
RainMachineProgram(
client,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the existing formatting, by having as many parameters on one line as possible.

from regenmaschine import Authenticator, Client
from regenmaschine.exceptions import HTTPError

_LOGGER.debug('Config data: %s', config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will log the whole config. Please remove.

_LOGGER.debug('Config data: %s', config)

conf = config[DOMAIN]
ip_address = conf.get(CONF_IP_ADDRESS, None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is the default value returned.

Copy link
Contributor Author

@bachya bachya Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by this; all other components I've looked at return True or False. Are you saying that I should be returning None, or that I shouldn't and I somehow am?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dict.get(key) by default returns None if the key is missing in the dict. So please just write conf.get(CONF_IP_ADDRESS).

Sorry about not being clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! Will update.

port = conf[CONF_PORT]
ssl = conf[CONF_SSL]
auth = Authenticator.create_local(
ip_address,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep as many arguments as possible on one line.

password,
port=port,
https=ssl)
_LOGGER.debug('Configuring local API: %s', auth)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this log credentials? If so remove.

_LOGGER.debug('Configuring local API: %s', auth)
elif email_address:
auth = Authenticator.create_remote(email_address, password)
_LOGGER.debug('Configuring remote API: %s', auth)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.


conf = config[DOMAIN]
ip_address = conf.get(CONF_IP_ADDRESS)
email_address = conf.get(CONF_EMAIL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed anymore with the new config schema.

_decorator = decorator
else:

@Throttle(MIN_SCAN_TIME_REMOTE, MIN_SCAN_TIME_FORCED)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be removed.

auth = Authenticator.create_local(
ip_address, password, port=port, https=ssl)
_LOGGER.debug('Configuring local API: %s', ip_address)
elif email_address:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

from regenmaschine.exceptions import HTTPError

conf = config[DOMAIN]
ip_address = conf.get(CONF_IP_ADDRESS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new schema this should be:

ip_address = conf[CONF_IP_ADDRESS]

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can be merged when build passes.

@MartinHjelmare MartinHjelmare changed the title Moves RainMachine to component/hub model Move RainMachine to component/hub model Apr 28, 2018
@MartinHjelmare MartinHjelmare merged commit 8bc497b into home-assistant:dev Apr 28, 2018
@bachya bachya deleted the rainmachine-1 branch April 30, 2018 21:02
@balloob balloob mentioned this pull request May 11, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants