Add config flow for rachio (#32757)

* Do not fail when a user has a controller with shared access on their account

* Add config flow for rachio

Also discoverable via homekit

* Update homeassistant/components/rachio/switch.py

Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>

* Split setting the default run time to an options flow

Ensue the run time coming from yaml gets imported into the option flow

Only get the schedule once at setup instead of each zone (was hitting rate limits)

Add the config entry id to the end of the webhook so there is a unique hook per config entry

Breakout the slew of exceptions rachiopy can throw into RachioAPIExceptions

Remove the base url override as an option for the config flow

Switch identifer for device_info to serial number

Add connections to device_info (mac address)

* rename to make pylint happy

* Fix import of custom_url

* claim rachio

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
J. Nick Koston 2020-03-14 00:46:17 -05:00 committed by GitHub
parent 743166d284
commit 7737387efe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 561 additions and 89 deletions

View file

@ -3,33 +3,41 @@ from abc import abstractmethod
import logging
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.helpers import device_registry
from homeassistant.helpers.dispatcher import dispatcher_connect
from . import (
DOMAIN as DOMAIN_RACHIO,
KEY_DEVICE_ID,
KEY_STATUS,
KEY_SUBTYPE,
SIGNAL_RACHIO_CONTROLLER_UPDATE,
STATUS_OFFLINE,
STATUS_ONLINE,
SUBTYPE_OFFLINE,
SUBTYPE_ONLINE,
)
from .const import (
DEFAULT_NAME,
DOMAIN as DOMAIN_RACHIO,
KEY_DEVICE_ID,
KEY_STATUS,
KEY_SUBTYPE,
)
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Rachio binary sensors."""
devices = []
for controller in hass.data[DOMAIN_RACHIO].controllers:
devices.append(RachioControllerOnlineBinarySensor(hass, controller))
add_entities(devices)
devices = await hass.async_add_executor_job(_create_devices, hass, config_entry)
async_add_entities(devices)
_LOGGER.info("%d Rachio binary sensor(s) added", len(devices))
def _create_devices(hass, config_entry):
devices = []
for controller in hass.data[DOMAIN_RACHIO][config_entry.entry_id].controllers:
devices.append(RachioControllerOnlineBinarySensor(hass, controller))
return devices
class RachioControllerBinarySensor(BinarySensorDevice):
"""Represent a binary sensor that reflects a Rachio state."""
@ -70,6 +78,18 @@ class RachioControllerBinarySensor(BinarySensorDevice):
"""Request the state from the API."""
pass
@property
def device_info(self):
"""Return the device_info of the device."""
return {
"identifiers": {(DOMAIN_RACHIO, self._controller.serial_number,)},
"connections": {
(device_registry.CONNECTION_NETWORK_MAC, self._controller.mac_address,)
},
"name": self._controller.name,
"manufacturer": DEFAULT_NAME,
}
@abstractmethod
def _handle_update(self, *args, **kwargs) -> None:
"""Handle an update to the state of this sensor."""