Move raincloud base entity to separate module (#126170)

This commit is contained in:
epenet 2024-09-18 11:23:10 +02:00 committed by GitHub
parent b1ef91bcfe
commit 3fb92bc245
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 72 additions and 68 deletions

View file

@ -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)

View file

@ -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__)

View file

@ -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)

View file

@ -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__)

View file

@ -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__)