Move HydrawiseEntity into entity.py (#93359)

This commit is contained in:
David Knowles 2023-05-22 09:47:32 -04:00 committed by GitHub
parent 9eca234948
commit 4d44d60e73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 36 deletions

View file

@ -6,10 +6,9 @@ import voluptuous as vol
from homeassistant.components import persistent_notification
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
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.dispatcher import dispatcher_send
from homeassistant.helpers.event import track_time_interval
from homeassistant.helpers.typing import ConfigType
@ -73,33 +72,3 @@ class HydrawiseHub:
def __init__(self, data):
"""Initialize the entity."""
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")}

View file

@ -15,8 +15,8 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import HydrawiseEntity
from .const import DATA_HYDRAWISE, LOGGER
from .entity import HydrawiseEntity
BINARY_SENSOR_STATUS = BinarySensorEntityDescription(
key="status",

View 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")}

View file

@ -16,8 +16,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import dt
from . import HydrawiseEntity
from .const import DATA_HYDRAWISE, LOGGER
from .entity import HydrawiseEntity
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(

View file

@ -17,7 +17,6 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import HydrawiseEntity
from .const import (
ALLOWED_WATERING_TIME,
CONF_WATERING_TIME,
@ -25,6 +24,7 @@ from .const import (
DEFAULT_WATERING_TIME,
LOGGER,
)
from .entity import HydrawiseEntity
SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
SwitchEntityDescription(