Move raincloud base entity to separate module (#126170)
This commit is contained in:
parent
b1ef91bcfe
commit
3fb92bc245
5 changed files with 72 additions and 68 deletions
|
@ -11,8 +11,7 @@ from homeassistant.components import persistent_notification
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
from homeassistant.helpers.event import track_time_interval
|
from homeassistant.helpers.event import track_time_interval
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
|
@ -25,29 +24,6 @@ NOTIFICATION_TITLE = "Rain Cloud Setup"
|
||||||
|
|
||||||
DOMAIN = "raincloud"
|
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)
|
SCAN_INTERVAL = timedelta(seconds=20)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
|
@ -104,43 +80,3 @@ class RainCloudHub:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
self.data = data
|
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)
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import RainCloudEntity
|
|
||||||
from .const import DATA_RAINCLOUD, ICON_MAP
|
from .const import DATA_RAINCLOUD, ICON_MAP
|
||||||
|
from .entity import RainCloudEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
68
homeassistant/components/raincloud/entity.py
Normal file
68
homeassistant/components/raincloud/entity.py
Normal 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)
|
|
@ -17,8 +17,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.icon import icon_for_battery_level
|
from homeassistant.helpers.icon import icon_for_battery_level
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import RainCloudEntity
|
|
||||||
from .const import DATA_RAINCLOUD, ICON_MAP
|
from .const import DATA_RAINCLOUD, ICON_MAP
|
||||||
|
from .entity import RainCloudEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@ import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import RainCloudEntity
|
|
||||||
from .const import DATA_RAINCLOUD
|
from .const import DATA_RAINCLOUD
|
||||||
|
from .entity import RainCloudEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue