Move HydrawiseEntity into entity.py (#93359)
This commit is contained in:
parent
9eca234948
commit
4d44d60e73
5 changed files with 42 additions and 36 deletions
|
@ -6,10 +6,9 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import persistent_notification
|
from homeassistant.components import persistent_notification
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_SCAN_INTERVAL
|
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_SCAN_INTERVAL
|
||||||
from homeassistant.core import HomeAssistant, callback
|
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, EntityDescription
|
|
||||||
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
|
||||||
|
|
||||||
|
@ -73,33 +72,3 @@ class HydrawiseHub:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
|
|
||||||
class HydrawiseEntity(Entity):
|
|
||||||
"""Entity class for Hydrawise devices."""
|
|
||||||
|
|
||||||
_attr_attribution = "Data provided by hydrawise.com"
|
|
||||||
|
|
||||||
def __init__(self, data, description: EntityDescription) -> None:
|
|
||||||
"""Initialize the Hydrawise entity."""
|
|
||||||
self.entity_description = description
|
|
||||||
self.data = data
|
|
||||||
self._attr_name = f"{self.data['name']} {description.name}"
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
|
||||||
"""Register callbacks."""
|
|
||||||
self.async_on_remove(
|
|
||||||
async_dispatcher_connect(
|
|
||||||
self.hass, SIGNAL_UPDATE_HYDRAWISE, self._update_callback
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def _update_callback(self):
|
|
||||||
"""Call update method."""
|
|
||||||
self.async_schedule_update_ha_state(True)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
return {"identifier": self.data.get("relay")}
|
|
||||||
|
|
|
@ -15,8 +15,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 HydrawiseEntity
|
|
||||||
from .const import DATA_HYDRAWISE, LOGGER
|
from .const import DATA_HYDRAWISE, LOGGER
|
||||||
|
from .entity import HydrawiseEntity
|
||||||
|
|
||||||
BINARY_SENSOR_STATUS = BinarySensorEntityDescription(
|
BINARY_SENSOR_STATUS = BinarySensorEntityDescription(
|
||||||
key="status",
|
key="status",
|
||||||
|
|
37
homeassistant/components/hydrawise/entity.py
Normal file
37
homeassistant/components/hydrawise/entity.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
"""Base classes for Hydrawise entities."""
|
||||||
|
|
||||||
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||||
|
|
||||||
|
from .const import SIGNAL_UPDATE_HYDRAWISE
|
||||||
|
|
||||||
|
|
||||||
|
class HydrawiseEntity(Entity):
|
||||||
|
"""Entity class for Hydrawise devices."""
|
||||||
|
|
||||||
|
_attr_attribution = "Data provided by hydrawise.com"
|
||||||
|
|
||||||
|
def __init__(self, data, description: EntityDescription) -> None:
|
||||||
|
"""Initialize the Hydrawise entity."""
|
||||||
|
self.entity_description = description
|
||||||
|
self.data = data
|
||||||
|
self._attr_name = f"{self.data['name']} {description.name}"
|
||||||
|
|
||||||
|
async def async_added_to_hass(self):
|
||||||
|
"""Register callbacks."""
|
||||||
|
self.async_on_remove(
|
||||||
|
async_dispatcher_connect(
|
||||||
|
self.hass, SIGNAL_UPDATE_HYDRAWISE, self._update_callback
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _update_callback(self):
|
||||||
|
"""Call update method."""
|
||||||
|
self.async_schedule_update_ha_state(True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def extra_state_attributes(self):
|
||||||
|
"""Return the state attributes."""
|
||||||
|
return {"identifier": self.data.get("relay")}
|
|
@ -16,8 +16,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.util import dt
|
from homeassistant.util import dt
|
||||||
|
|
||||||
from . import HydrawiseEntity
|
|
||||||
from .const import DATA_HYDRAWISE, LOGGER
|
from .const import DATA_HYDRAWISE, LOGGER
|
||||||
|
from .entity import HydrawiseEntity
|
||||||
|
|
||||||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
|
|
|
@ -17,7 +17,6 @@ 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 HydrawiseEntity
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ALLOWED_WATERING_TIME,
|
ALLOWED_WATERING_TIME,
|
||||||
CONF_WATERING_TIME,
|
CONF_WATERING_TIME,
|
||||||
|
@ -25,6 +24,7 @@ from .const import (
|
||||||
DEFAULT_WATERING_TIME,
|
DEFAULT_WATERING_TIME,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
)
|
)
|
||||||
|
from .entity import HydrawiseEntity
|
||||||
|
|
||||||
SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
|
SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
|
||||||
SwitchEntityDescription(
|
SwitchEntityDescription(
|
||||||
|
|
Loading…
Add table
Reference in a new issue