Skip to content

Rachio (Sprinklers)#7600

Merged
fabaff merged 11 commits into
home-assistant:devfrom
Klikini:dev
May 29, 2017
Merged

Rachio (Sprinklers)#7600
fabaff merged 11 commits into
home-assistant:devfrom
Klikini:dev

Conversation

@Klikini
Copy link
Copy Markdown
Contributor

@Klikini Klikini commented May 15, 2017

Description:

Pull request in Content for (I don't exactly know how it works) home-assistant.github.io with documentation: https://github.com/Klikini/home-assistant.github.io/issues/2

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

Example entry for configuration.yaml:

switch:
  - platform: rachio
    access_token: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    manual_run_mins: 10

Checklist:

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

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

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable.
  • New dependencies are only imported inside functions that use them.
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.
  • Fix this bug for is_on

@homeassistant
Copy link
Copy Markdown
Contributor

Hi @Klikini,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

headers = self.r.device.stopWater(self._device.device_id)[0]
self.update(no_throttle=True)
return headers

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blank line at end of file

@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented May 15, 2017

rachiopy uses the MIT license

Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

You've checked the boxes in your PR that you added the file to .coveragerc and ran script/gen_requirements_all.py. Both those changes should be part of this PR too.

# Set up the component
# noinspection PyUnusedLocal
def setup_platform(hass, config, add_devices, discovery_info=None):
global _IRO
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't use global, use hass.data[DATA_RACHIO ] instead, which is a dict for this purpose.

from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
from homeassistant.const import CONF_ACCESS_TOKEN

REQUIREMENTS = ['https://github.com/Klikini/rachiopy'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you push your dependency to PyPi?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this fork is intended to stay as a permanent code, could you push it to pypi?

_LOGGER.debug("Configuring Rachio API...")
from rachiopy import Rachio
r = Rachio(access_token)
person = _get_person(r)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will you be able to verify that the given API token is valid?



# Represents one Rachio Iro
class RachioIro(object):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would have expected this class to live in RachioPy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

RachioPy is not my own creation, and in fact includes these classes, however, they only contain static methods and are otherwise useless. I'll add these methods to my fork of the library.

return False

# Pull updated zone info from the Rachio API
@util.Throttle(MIN_UPDATE_INTERVAL, MIN_FORCED_UPDATE_INTERVAL)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why would you throttle this? The device property that fetches the data is already throttled.

Copy link
Copy Markdown
Contributor Author

@Klikini Klikini May 15, 2017

Choose a reason for hiding this comment

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

Oh, okay. I didn't know how it works. This file contains every existing line of Python that I've written in my life.

👍


_LOGGER.info("Watering {} for {} sec".format(self.name, seconds))
headers = self.r.zone.start(self.zone_id, seconds)[0]
self.update(no_throttle=True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Home Assistant will automatically call update on your entity after calling turn_on or turn_off

def is_on(self):
self._device.update(propagate=False)
schedule = self._device.current_schedule
if 'zoneId' in schedule:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

get returns the value of a dictionary or None if not found. So you can replace this if…else with return self.zone_id == schedule.get('zoneId')

global manual_run_mins

# Get options
manual_run_mins = config.get(CONF_manual_run_mins) or manual_run_mins
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This config parameter is not referenced in PLATFORM_SCHEMA

CONF_manual_run_mins = 'manual_run_mins'
manual_run_mins = 60

STATUS_ONLINE = 'ONLINE'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not being used


_LOGGER = logging.getLogger(__name__)

DOMAIN = 'switch'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not being used.

@balloob
Copy link
Copy Markdown
Member

balloob commented May 15, 2017

Also, your documentation PR should be a PR against our documentation repository at https://github.com/home-assistant/home-assistant.github.io

Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Alright, already looking a lot better! Found some more things that need fixing.

# Set up the component
# noinspection PyUnusedLocal
def setup_platform(hass, config, add_devices, discovery_info=None):
global manual_run_mins
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please do not use global


# Get options
manual_run_mins = config.get(CONF_MANUAL_RUN_MINS) or manual_run_mins
_LOGGER.debug("Rachio run time is " + str(manual_run_mins) + " min")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This, among other things, is one of the many lint issues that CI is reporting that need to be fixed: https://travis-ci.org/home-assistant/home-assistant/jobs/233033184#L271

# Get access token
_LOGGER.debug("Getting Rachio access token...")
access_token = config.get(CONF_ACCESS_TOKEN)
if not access_token:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is impossible, it's marked as required in your PLATFORM_SCHEMA


@property
def name(self):
return self._zone['name'] or "Zone " + self.number
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If _zone['name'] does not exist, a KeyError will be raised. Use _zone.get('name') instead to get None back.

Copy link
Copy Markdown
Contributor Author

@Klikini Klikini May 17, 2017

Choose a reason for hiding this comment

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

👍

Looks like this was unnecessary anyway. The API returns a placeholder name already, so I don't need to make one.

self._zone = self.r.zone.get(self._zone_id)[1]

# Possibly update device
if propagate:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Your entity is set to be polled for updates by Home Assistant (because you do not overwrite the should_poll property). Each entity will individually call _device.update(), which is fine because Throttle will take care of it only getting called once.

So you can remove the whole propagation of updates.

Comment thread tests/testing_config/automations.yaml Outdated
@@ -0,0 +1 @@
[] No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove this file.

def update(self):
"""Pull updated device info from the Rachio API."""
self._device = self.rachio.device.get(self._device_id)[1]
self._running = self.rachio.device.getCurrentSchedule(self._device_id)[1]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

@balloob
Copy link
Copy Markdown
Member

balloob commented May 23, 2017

Please remove the polymer submodule from your commits.

Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Ok to merge when polymer change has been removed from pr.

@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented May 24, 2017

And for everything not yet handled by this component (read: most things), the iframe feature works well with the Rachio webapp:

image

@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented May 24, 2017

I just remembered I made a change in my fork of RachioPy to get around an issue for testing and I need to figure out how to verify HTTP SSL certs in a thread before this merges.

DO NOT MERGE YET, it could create the opportunity for a man-in-the-middle attack between the HomeAssistant instance and Rachio's API.

@fabaff
Copy link
Copy Markdown
Member

fabaff commented May 29, 2017

@fabaff fabaff merged commit fc1bb58 into home-assistant:dev May 29, 2017
@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented Jun 1, 2017

I know this is closed, but I wanted to write it here so I can remember.

The switch shows the correct state when a schedule is running:

image

But it doesn't detect manual runs (so it appears to switch off after being turned on)

@brg468
Copy link
Copy Markdown
Contributor

brg468 commented Jun 1, 2017

I found an issue with the way manual runs are handled from within HA. Your turn_on method is multiplying manual_run_secs by 60, but that number is already minutes multiplied by 60 during the init, which is causing the manual_run_min to be multiplied by 3600. Putting any number longer than 3 in for manual run wont work because its over the max of 10800 seconds (that's how I discovered the problem). Obviously removing one of those multiplications fixes the problem.
Glad you got this up and running!

 def __init__(self, rachio, device, zone_id, manual_run_mins):
        """Initialize a new Rachio Zone."""
        self.rachio = rachio
        self._device = device
        self._zone_id = zone_id
        self._zone = None
        self._manual_run_secs = manual_run_mins * 60
 def turn_on(self):
        """Start the zone."""
        # Convert minutes to seconds
        seconds = self._manual_run_secs * 60

        # Stop other zones first
        self.turn_off()

        _LOGGER.info("Watering %s for %d sec", self.name, seconds)
        self.rachio.zone.start(self.zone_id, seconds)

@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented Jun 1, 2017

f001724

@balloob balloob mentioned this pull request Jun 2, 2017
@scadagenius
Copy link
Copy Markdown

Nice addition to HA. Hope in future we will have rain sensor input as well.

@brg468
Copy link
Copy Markdown
Contributor

brg468 commented Jun 4, 2017

You fixed the double convert, but in doing so you removed the 'seconds' variable, which is still trying to be called by the turn_on method. 😄

@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented Jun 4, 2017

@scadaguru At some point I need to break out the actual device/zone code into a platform, and then replace the switch code with calls to that. Once that's done, it'll be a easier to add sensors with it as well.

@scadagenius
Copy link
Copy Markdown

@Klikini that will be so nice. I am already enjoying now. Google Home will be watering my landscape now!
Thanks

@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented Jun 4, 2017

@mririgoyen
Copy link
Copy Markdown
Contributor

@Klikini FYI: https://community.home-assistant.io/t/rachio-in-0-46-0/19185

Looks like there are some pretty serious problems with this component.

@Klikini Klikini mentioned this pull request Jun 5, 2017
5 tasks
@home-assistant home-assistant locked and limited conversation to collaborators Sep 4, 2017
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.