Add Rainmachine config entry (#18419)

* Initial stuff

* More work in place

* Starting with tests

* Device registry in place

* Hound

* Linting

* Member comments (including extracting device registry)

* Member comments (plus I forgot cleanup!)

* Hound

* More Hound

* Removed old import

* Adding config entry test to coverage

* Updated strings
This commit is contained in:
Aaron Bach authored and GitHub committed 2018-11-14 13:23:49 -07:00
1 parent 312872961f
commit 8aa1283adc
15 files changed
+400 -87

No files matched your search

+16 -11
View File
@@ -7,8 +7,8 @@ https://home-assistant.io/components/switch.rainmachine/
import logging
from homeassistant.components.rainmachine import (
CONF_ZONE_RUN_TIME, DATA_RAINMACHINE, DEFAULT_ZONE_RUN,
PROGRAM_UPDATE_TOPIC, ZONE_UPDATE_TOPIC, RainMachineEntity)
DATA_CLIENT, DOMAIN as RAINMACHINE_DOMAIN, PROGRAM_UPDATE_TOPIC,
ZONE_UPDATE_TOPIC, RainMachineEntity)
from homeassistant.const import ATTR_ID
from homeassistant.components.switch import SwitchDevice
from homeassistant.core import callback
@@ -101,15 +101,13 @@ VEGETATION_MAP = {
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None):
"""Set up the RainMachine Switch platform."""
if discovery_info is None:
return
"""Set up RainMachine switches sensor based on the old way."""
pass
_LOGGER.debug('Config received: %s', discovery_info)
zone_run_time = discovery_info.get(CONF_ZONE_RUN_TIME, DEFAULT_ZONE_RUN)
rainmachine = hass.data[DATA_RAINMACHINE]
async def async_setup_entry(hass, entry, async_add_entities):
"""Set up RainMachine switches based on a config entry."""
rainmachine = hass.data[RAINMACHINE_DOMAIN][DATA_CLIENT][entry.entry_id]
entities = []
@@ -127,7 +125,9 @@ async def async_setup_platform(
continue
_LOGGER.debug('Adding zone: %s', zone)
entities.append(RainMachineZone(rainmachine, zone, zone_run_time))
entities.append(
RainMachineZone(
rainmachine, zone, rainmachine.default_zone_runtime))
async_add_entities(entities, True)
@@ -186,9 +186,14 @@ class RainMachineProgram(RainMachineSwitch):
async def async_added_to_hass(self):
"""Register callbacks."""
async_dispatcher_connect(
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
self.hass, PROGRAM_UPDATE_TOPIC, self._program_updated)
async def async_will_remove_from_hass(self):
"""Disconnect dispatcher listener when removed."""
if self._async_unsub_dispatcher_connect:
self._async_unsub_dispatcher_connect()
async def async_turn_off(self, **kwargs) -> None:
"""Turn the program off."""
from regenmaschine.errors import RequestError