Rachio component modernization (#16911)
Add `unique_id` to all rachio entities Add platform discovery to rachio component Move config options from switch.rachio platform to the rachio component
This commit is contained in:
parent
f879ac0993
commit
9abdbf3db6
3 changed files with 38 additions and 17 deletions
|
@ -7,10 +7,10 @@ https://home-assistant.io/components/switch.rachio/
|
|||
from abc import abstractmethod
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
|
||||
from homeassistant.components.rachio import (DOMAIN as DOMAIN_RACHIO,
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.components.rachio import (CONF_MANUAL_RUN_MINS,
|
||||
DOMAIN as DOMAIN_RACHIO,
|
||||
KEY_DEVICE_ID,
|
||||
KEY_ENABLED,
|
||||
KEY_ID,
|
||||
|
@ -27,29 +27,20 @@ from homeassistant.components.rachio import (DOMAIN as DOMAIN_RACHIO,
|
|||
SUBTYPE_ZONE_COMPLETED,
|
||||
SUBTYPE_SLEEP_MODE_ON,
|
||||
SUBTYPE_SLEEP_MODE_OFF)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import dispatcher_connect
|
||||
|
||||
DEPENDENCIES = ['rachio']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Manual run length
|
||||
CONF_MANUAL_RUN_MINS = 'manual_run_mins'
|
||||
DEFAULT_MANUAL_RUN_MINS = 10
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Optional(CONF_MANUAL_RUN_MINS, default=DEFAULT_MANUAL_RUN_MINS):
|
||||
cv.positive_int,
|
||||
})
|
||||
|
||||
ATTR_ZONE_SUMMARY = 'Summary'
|
||||
ATTR_ZONE_NUMBER = 'Zone number'
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Rachio switches."""
|
||||
manual_run_time = timedelta(minutes=config.get(CONF_MANUAL_RUN_MINS))
|
||||
manual_run_time = timedelta(minutes=hass.data[DOMAIN_RACHIO].config.get(
|
||||
CONF_MANUAL_RUN_MINS))
|
||||
_LOGGER.info("Rachio run time is %s", str(manual_run_time))
|
||||
|
||||
# Add all zones from all controllers as switches
|
||||
|
@ -126,6 +117,11 @@ class RachioStandbySwitch(RachioSwitch):
|
|||
"""Return the name of the standby switch."""
|
||||
return "{} in standby mode".format(self._controller.name)
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique id by combinining controller id and purpose."""
|
||||
return "{}-standby".format(self._controller.controller_id)
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return an icon for the standby switch."""
|
||||
|
@ -189,6 +185,12 @@ class RachioZone(RachioSwitch):
|
|||
"""Return the friendly name of the zone."""
|
||||
return self._zone_name
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique id by combinining controller id and zone number."""
|
||||
return "{}-zone-{}".format(self._controller.controller_id,
|
||||
self.zone_id)
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon to display."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue