Add base entity class in vicare integration (#101870)
* add entity base class * depend on base class * add device info to base class * remove individual DeviceInfo * move class * fix imports * add file comment * use super() * fix formatting * add vicare/entity.pypull/101879/head
parent
3e4edc8edd
commit
6e1c23906c
|
@ -1470,6 +1470,7 @@ omit =
|
|||
homeassistant/components/vicare/binary_sensor.py
|
||||
homeassistant/components/vicare/button.py
|
||||
homeassistant/components/vicare/climate.py
|
||||
homeassistant/components/vicare/entity.py
|
||||
homeassistant/components/vicare/sensor.py
|
||||
homeassistant/components/vicare/water_heater.py
|
||||
homeassistant/components/vilfo/__init__.py
|
||||
|
|
|
@ -19,11 +19,11 @@ from homeassistant.components.binary_sensor import (
|
|||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ViCareRequiredKeysMixin
|
||||
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG, VICARE_NAME
|
||||
from .entity import ViCareEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -182,7 +182,7 @@ async def async_setup_entry(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ViCareBinarySensor(BinarySensorEntity):
|
||||
class ViCareBinarySensor(ViCareEntity, BinarySensorEntity):
|
||||
"""Representation of a ViCare sensor."""
|
||||
|
||||
entity_description: ViCareBinarySensorEntityDescription
|
||||
|
@ -191,18 +191,11 @@ class ViCareBinarySensor(BinarySensorEntity):
|
|||
self, name, api, device_config, description: ViCareBinarySensorEntityDescription
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(device_config)
|
||||
self.entity_description = description
|
||||
self._attr_name = name
|
||||
self._api = api
|
||||
self.entity_description = description
|
||||
self._device_config = device_config
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device_config.getConfig().serial)},
|
||||
name=device_config.getModel(),
|
||||
manufacturer="Viessmann",
|
||||
model=device_config.getModel(),
|
||||
configuration_url="https://developer.viessmann.com/",
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
|
|
|
@ -16,11 +16,11 @@ from homeassistant.components.button import ButtonEntity, ButtonEntityDescriptio
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ViCareRequiredKeysMixinWithSet
|
||||
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG, VICARE_NAME
|
||||
from .entity import ViCareEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -92,7 +92,7 @@ async def async_setup_entry(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ViCareButton(ButtonEntity):
|
||||
class ViCareButton(ViCareEntity, ButtonEntity):
|
||||
"""Representation of a ViCare button."""
|
||||
|
||||
entity_description: ViCareButtonEntityDescription
|
||||
|
@ -101,16 +101,10 @@ class ViCareButton(ButtonEntity):
|
|||
self, name, api, device_config, description: ViCareButtonEntityDescription
|
||||
) -> None:
|
||||
"""Initialize the button."""
|
||||
super().__init__(device_config)
|
||||
self.entity_description = description
|
||||
self._device_config = device_config
|
||||
self._api = api
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device_config.getConfig().serial)},
|
||||
name=device_config.getModel(),
|
||||
manufacturer="Viessmann",
|
||||
model=device_config.getModel(),
|
||||
configuration_url="https://developer.viessmann.com/",
|
||||
)
|
||||
|
||||
def press(self) -> None:
|
||||
"""Handle the button press."""
|
||||
|
|
|
@ -33,10 +33,10 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_platform
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG, VICARE_NAME
|
||||
from .entity import ViCareEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -134,7 +134,7 @@ async def async_setup_entry(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ViCareClimate(ClimateEntity):
|
||||
class ViCareClimate(ViCareEntity, ClimateEntity):
|
||||
"""Representation of the ViCare heating climate device."""
|
||||
|
||||
_attr_precision = PRECISION_TENTHS
|
||||
|
@ -149,6 +149,7 @@ class ViCareClimate(ClimateEntity):
|
|||
|
||||
def __init__(self, name, api, circuit, device_config):
|
||||
"""Initialize the climate device."""
|
||||
super().__init__(device_config)
|
||||
self._attr_name = name
|
||||
self._api = api
|
||||
self._circuit = circuit
|
||||
|
@ -157,13 +158,6 @@ class ViCareClimate(ClimateEntity):
|
|||
self._current_program = None
|
||||
self._current_action = None
|
||||
self._attr_unique_id = f"{device_config.getConfig().serial}-{circuit.id}"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device_config.getConfig().serial)},
|
||||
name=device_config.getModel(),
|
||||
manufacturer="Viessmann",
|
||||
model=device_config.getModel(),
|
||||
configuration_url="https://developer.viessmann.com/",
|
||||
)
|
||||
|
||||
def update(self) -> None:
|
||||
"""Let HA know there has been an update from the ViCare API."""
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
"""Entities for the ViCare integration."""
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
class ViCareEntity(Entity):
|
||||
"""Base class for ViCare entities."""
|
||||
|
||||
def __init__(self, device_config) -> None:
|
||||
"""Initialize the entity."""
|
||||
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device_config.getConfig().serial)},
|
||||
name=device_config.getModel(),
|
||||
manufacturer="Viessmann",
|
||||
model=device_config.getModel(),
|
||||
configuration_url="https://developer.viessmann.com/",
|
||||
)
|
|
@ -30,7 +30,6 @@ from homeassistant.const import (
|
|||
UnitOfVolume,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ViCareRequiredKeysMixin
|
||||
|
@ -43,6 +42,7 @@ from .const import (
|
|||
VICARE_NAME,
|
||||
VICARE_UNIT_TO_UNIT_OF_MEASUREMENT,
|
||||
)
|
||||
from .entity import ViCareEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -660,7 +660,7 @@ async def async_setup_entry(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ViCareSensor(SensorEntity):
|
||||
class ViCareSensor(ViCareEntity, SensorEntity):
|
||||
"""Representation of a ViCare sensor."""
|
||||
|
||||
entity_description: ViCareSensorEntityDescription
|
||||
|
@ -669,22 +669,12 @@ class ViCareSensor(SensorEntity):
|
|||
self, name, api, device_config, description: ViCareSensorEntityDescription
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(device_config)
|
||||
self.entity_description = description
|
||||
self._attr_name = name
|
||||
self._api = api
|
||||
self._device_config = device_config
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info for this device."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device_config.getConfig().serial)},
|
||||
name=self._device_config.getModel(),
|
||||
manufacturer="Viessmann",
|
||||
model=self._device_config.getModel(),
|
||||
configuration_url="https://developer.viessmann.com/",
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if entity is available."""
|
||||
|
|
|
@ -17,10 +17,10 @@ from homeassistant.components.water_heater import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG, VICARE_NAME
|
||||
from .entity import ViCareEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -90,7 +90,7 @@ async def async_setup_entry(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ViCareWater(WaterHeaterEntity):
|
||||
class ViCareWater(ViCareEntity, WaterHeaterEntity):
|
||||
"""Representation of the ViCare domestic hot water device."""
|
||||
|
||||
_attr_precision = PRECISION_TENTHS
|
||||
|
@ -102,19 +102,13 @@ class ViCareWater(WaterHeaterEntity):
|
|||
|
||||
def __init__(self, name, api, circuit, device_config):
|
||||
"""Initialize the DHW water_heater device."""
|
||||
super().__init__(device_config)
|
||||
self._attr_name = name
|
||||
self._api = api
|
||||
self._circuit = circuit
|
||||
self._attributes = {}
|
||||
self._current_mode = None
|
||||
self._attr_unique_id = f"{device_config.getConfig().serial}-{circuit.id}"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device_config.getConfig().serial)},
|
||||
name=device_config.getModel(),
|
||||
manufacturer="Viessmann",
|
||||
model=device_config.getModel(),
|
||||
configuration_url="https://developer.viessmann.com/",
|
||||
)
|
||||
|
||||
def update(self) -> None:
|
||||
"""Let HA know there has been an update from the ViCare API."""
|
||||
|
|
Loading…
Reference in New Issue