diff --git a/homeassistant/components/raincloud/__init__.py b/homeassistant/components/raincloud/__init__.py index 56f1cff2e99..f1eef40f307 100644 --- a/homeassistant/components/raincloud/__init__.py +++ b/homeassistant/components/raincloud/__init__.py @@ -11,8 +11,7 @@ from homeassistant.components import persistent_notification from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.dispatcher import dispatcher_send from homeassistant.helpers.event import track_time_interval from homeassistant.helpers.typing import ConfigType @@ -25,29 +24,6 @@ NOTIFICATION_TITLE = "Rain Cloud Setup" DOMAIN = "raincloud" -KEY_MAP = { - "auto_watering": "Automatic Watering", - "battery": "Battery", - "is_watering": "Watering", - "manual_watering": "Manual Watering", - "next_cycle": "Next Cycle", - "rain_delay": "Rain Delay", - "status": "Status", - "watering_time": "Remaining Watering Time", -} - -ICON_MAP = { - "auto_watering": "mdi:autorenew", - "battery": "", - "is_watering": "", - "manual_watering": "mdi:water-pump", - "next_cycle": "mdi:calendar-clock", - "rain_delay": "mdi:weather-rainy", - "status": "", - "watering_time": "mdi:water-pump", -} - - SCAN_INTERVAL = timedelta(seconds=20) CONFIG_SCHEMA = vol.Schema( @@ -104,43 +80,3 @@ class RainCloudHub: def __init__(self, data): """Initialize the entity.""" self.data = data - - -class RainCloudEntity(Entity): - """Entity class for RainCloud devices.""" - - _attr_attribution = "Data provided by Melnor Aquatimer.com" - - def __init__(self, data, sensor_type): - """Initialize the RainCloud entity.""" - self.data = data - self._sensor_type = sensor_type - self._name = f"{self.data.name} {KEY_MAP.get(self._sensor_type)}" - self._state = None - - @property - def name(self): - """Return the name of the sensor.""" - return self._name - - async def async_added_to_hass(self): - """Register callbacks.""" - self.async_on_remove( - async_dispatcher_connect( - self.hass, SIGNAL_UPDATE_RAINCLOUD, self._update_callback - ) - ) - - def _update_callback(self): - """Call update method.""" - self.schedule_update_ha_state(True) - - @property - def extra_state_attributes(self): - """Return the state attributes.""" - return {"identifier": self.data.serial} - - @property - def icon(self): - """Return the icon to use in the frontend, if any.""" - return ICON_MAP.get(self._sensor_type) diff --git a/homeassistant/components/raincloud/binary_sensor.py b/homeassistant/components/raincloud/binary_sensor.py index 90e8cc99240..2696c192ed6 100644 --- a/homeassistant/components/raincloud/binary_sensor.py +++ b/homeassistant/components/raincloud/binary_sensor.py @@ -16,8 +16,8 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from . import RainCloudEntity from .const import DATA_RAINCLOUD, ICON_MAP +from .entity import RainCloudEntity _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/raincloud/entity.py b/homeassistant/components/raincloud/entity.py new file mode 100644 index 00000000000..337324d96eb --- /dev/null +++ b/homeassistant/components/raincloud/entity.py @@ -0,0 +1,68 @@ +"""Support for Melnor RainCloud sprinkler water timer.""" + +from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import Entity + +from .const import SIGNAL_UPDATE_RAINCLOUD + +KEY_MAP = { + "auto_watering": "Automatic Watering", + "battery": "Battery", + "is_watering": "Watering", + "manual_watering": "Manual Watering", + "next_cycle": "Next Cycle", + "rain_delay": "Rain Delay", + "status": "Status", + "watering_time": "Remaining Watering Time", +} + +ICON_MAP = { + "auto_watering": "mdi:autorenew", + "battery": "", + "is_watering": "", + "manual_watering": "mdi:water-pump", + "next_cycle": "mdi:calendar-clock", + "rain_delay": "mdi:weather-rainy", + "status": "", + "watering_time": "mdi:water-pump", +} + + +class RainCloudEntity(Entity): + """Entity class for RainCloud devices.""" + + _attr_attribution = "Data provided by Melnor Aquatimer.com" + + def __init__(self, data, sensor_type): + """Initialize the RainCloud entity.""" + self.data = data + self._sensor_type = sensor_type + self._name = f"{self.data.name} {KEY_MAP.get(self._sensor_type)}" + self._state = None + + @property + def name(self): + """Return the name of the sensor.""" + return self._name + + async def async_added_to_hass(self): + """Register callbacks.""" + self.async_on_remove( + async_dispatcher_connect( + self.hass, SIGNAL_UPDATE_RAINCLOUD, self._update_callback + ) + ) + + def _update_callback(self): + """Call update method.""" + self.schedule_update_ha_state(True) + + @property + def extra_state_attributes(self): + """Return the state attributes.""" + return {"identifier": self.data.serial} + + @property + def icon(self): + """Return the icon to use in the frontend, if any.""" + return ICON_MAP.get(self._sensor_type) diff --git a/homeassistant/components/raincloud/sensor.py b/homeassistant/components/raincloud/sensor.py index 6a7a45dbf37..1f9d8d7b2c5 100644 --- a/homeassistant/components/raincloud/sensor.py +++ b/homeassistant/components/raincloud/sensor.py @@ -17,8 +17,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.icon import icon_for_battery_level from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from . import RainCloudEntity from .const import DATA_RAINCLOUD, ICON_MAP +from .entity import RainCloudEntity _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/raincloud/switch.py b/homeassistant/components/raincloud/switch.py index 47a2de8afaa..59a11a6b167 100644 --- a/homeassistant/components/raincloud/switch.py +++ b/homeassistant/components/raincloud/switch.py @@ -17,8 +17,8 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from . import RainCloudEntity from .const import DATA_RAINCLOUD +from .entity import RainCloudEntity _LOGGER = logging.getLogger(__name__)