mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Move econet base entity to separate module (#126049)
This commit is contained in:
parent
9dd16d3df5
commit
4c5535d1cc
@ -16,14 +16,12 @@ from pyeconet.errors import (
|
|||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
|
|
||||||
from .const import API_CLIENT, DOMAIN, EQUIPMENT
|
from .const import API_CLIENT, DOMAIN, EQUIPMENT, PUSH_UPDATE
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -34,7 +32,6 @@ PLATFORMS = [
|
|||||||
Platform.SWITCH,
|
Platform.SWITCH,
|
||||||
Platform.WATER_HEATER,
|
Platform.WATER_HEATER,
|
||||||
]
|
]
|
||||||
PUSH_UPDATE = "econet.push_update"
|
|
||||||
|
|
||||||
INTERVAL = timedelta(minutes=60)
|
INTERVAL = timedelta(minutes=60)
|
||||||
|
|
||||||
@ -99,41 +96,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.data[DOMAIN][API_CLIENT].pop(entry.entry_id)
|
hass.data[DOMAIN][API_CLIENT].pop(entry.entry_id)
|
||||||
hass.data[DOMAIN][EQUIPMENT].pop(entry.entry_id)
|
hass.data[DOMAIN][EQUIPMENT].pop(entry.entry_id)
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
class EcoNetEntity(Entity):
|
|
||||||
"""Define a base EcoNet entity."""
|
|
||||||
|
|
||||||
_attr_should_poll = False
|
|
||||||
|
|
||||||
def __init__(self, econet):
|
|
||||||
"""Initialize."""
|
|
||||||
self._econet = econet
|
|
||||||
self._attr_name = econet.device_name
|
|
||||||
self._attr_unique_id = f"{econet.device_id}_{econet.device_name}"
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
|
||||||
"""Subscribe to device events."""
|
|
||||||
await super().async_added_to_hass()
|
|
||||||
self.async_on_remove(
|
|
||||||
async_dispatcher_connect(self.hass, PUSH_UPDATE, self.on_update_received)
|
|
||||||
)
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def on_update_received(self):
|
|
||||||
"""Update was pushed from the ecoent API."""
|
|
||||||
self.async_write_ha_state()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self):
|
|
||||||
"""Return if the device is online or not."""
|
|
||||||
return self._econet.connected
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return device registry information for this entity."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._econet.device_id)},
|
|
||||||
manufacturer="Rheem",
|
|
||||||
name=self._econet.device_name,
|
|
||||||
)
|
|
||||||
|
@ -13,8 +13,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import EcoNetEntity
|
|
||||||
from .const import DOMAIN, EQUIPMENT
|
from .const import DOMAIN, EQUIPMENT
|
||||||
|
from .entity import EcoNetEntity
|
||||||
|
|
||||||
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
||||||
BinarySensorEntityDescription(
|
BinarySensorEntityDescription(
|
||||||
|
@ -22,8 +22,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||||
|
|
||||||
from . import EcoNetEntity
|
|
||||||
from .const import DOMAIN, EQUIPMENT
|
from .const import DOMAIN, EQUIPMENT
|
||||||
|
from .entity import EcoNetEntity
|
||||||
|
|
||||||
ECONET_STATE_TO_HA = {
|
ECONET_STATE_TO_HA = {
|
||||||
ThermostatOperationMode.HEATING: HVACMode.HEAT,
|
ThermostatOperationMode.HEATING: HVACMode.HEAT,
|
||||||
|
@ -3,3 +3,5 @@
|
|||||||
DOMAIN = "econet"
|
DOMAIN = "econet"
|
||||||
API_CLIENT = "api_client"
|
API_CLIENT = "api_client"
|
||||||
EQUIPMENT = "equipment"
|
EQUIPMENT = "equipment"
|
||||||
|
|
||||||
|
PUSH_UPDATE = "econet.push_update"
|
||||||
|
46
homeassistant/components/econet/entity.py
Normal file
46
homeassistant/components/econet/entity.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
"""Support for EcoNet products."""
|
||||||
|
|
||||||
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
from .const import DOMAIN, PUSH_UPDATE
|
||||||
|
|
||||||
|
|
||||||
|
class EcoNetEntity(Entity):
|
||||||
|
"""Define a base EcoNet entity."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
|
def __init__(self, econet):
|
||||||
|
"""Initialize."""
|
||||||
|
self._econet = econet
|
||||||
|
self._attr_name = econet.device_name
|
||||||
|
self._attr_unique_id = f"{econet.device_id}_{econet.device_name}"
|
||||||
|
|
||||||
|
async def async_added_to_hass(self):
|
||||||
|
"""Subscribe to device events."""
|
||||||
|
await super().async_added_to_hass()
|
||||||
|
self.async_on_remove(
|
||||||
|
async_dispatcher_connect(self.hass, PUSH_UPDATE, self.on_update_received)
|
||||||
|
)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def on_update_received(self):
|
||||||
|
"""Update was pushed from the ecoent API."""
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return if the device is online or not."""
|
||||||
|
return self._econet.connected
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_info(self) -> DeviceInfo:
|
||||||
|
"""Return device registry information for this entity."""
|
||||||
|
return DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, self._econet.device_id)},
|
||||||
|
manufacturer="Rheem",
|
||||||
|
name=self._econet.device_name,
|
||||||
|
)
|
@ -21,8 +21,8 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import EcoNetEntity
|
|
||||||
from .const import DOMAIN, EQUIPMENT
|
from .const import DOMAIN, EQUIPMENT
|
||||||
|
from .entity import EcoNetEntity
|
||||||
|
|
||||||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
|
@ -13,8 +13,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import EcoNetEntity
|
|
||||||
from .const import DOMAIN, EQUIPMENT
|
from .const import DOMAIN, EQUIPMENT
|
||||||
|
from .entity import EcoNetEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF, UnitOfTemperature
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import EcoNetEntity
|
|
||||||
from .const import DOMAIN, EQUIPMENT
|
from .const import DOMAIN, EQUIPMENT
|
||||||
|
from .entity import EcoNetEntity
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(hours=1)
|
SCAN_INTERVAL = timedelta(hours=1)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user