Update sensor.py

This commit is contained in:
Christopher Fenner
2023-10-06 08:29:04 +02:00
committed by GitHub
parent 1bcc946256
commit 003faefb12

View File

@@ -575,7 +575,7 @@ COMPRESSOR_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
)
def _build_entity(name, vicare_api, device_config, sensor):
def _build_entity(name, vicare_api, device_config, sensor, hasMultipleDevices: bool):
"""Create a ViCare sensor entity."""
_LOGGER.debug("Found device %s", name)
try:
@@ -593,11 +593,12 @@ def _build_entity(name, vicare_api, device_config, sensor):
vicare_api,
device_config,
sensor,
hasMultipleDevices,
)
async def _entities_from_descriptions(
hass, entities, sensor_descriptions, iterables, device
hass, entities, sensor_descriptions, iterables, device, hasMultipleDevices: bool
):
"""Create entities from descriptions and list of burners/circuits."""
for description in sensor_descriptions:
@@ -611,6 +612,7 @@ async def _entities_from_descriptions(
current,
device,
description,
hasMultipleDevices,
)
if entity is not None:
entities.append(entity)
@@ -623,6 +625,7 @@ async def async_setup_entry(
) -> None:
"""Create the ViCare sensor devices."""
entities = []
hasMultipleDevices = len(hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_LIST]) > 1
for device in hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_LIST]:
api = getattr(
@@ -638,27 +641,28 @@ async def async_setup_entry(
api,
device,
description,
hasMultipleDevices,
)
if entity is not None:
entities.append(entity)
try:
await _entities_from_descriptions(
hass, entities, CIRCUIT_SENSORS, api.circuits, device
hass, entities, CIRCUIT_SENSORS, api.circuits, device, hasMultipleDevices
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No circuits found")
try:
await _entities_from_descriptions(
hass, entities, BURNER_SENSORS, api.burners, device
hass, entities, BURNER_SENSORS, api.burners, device, hasMultipleDevices
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No burners found")
try:
await _entities_from_descriptions(
hass, entities, COMPRESSOR_SENSORS, api.compressors, device
hass, entities, COMPRESSOR_SENSORS, api.compressors, device, hasMultipleDevices
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No compressors found")
@@ -666,31 +670,21 @@ async def async_setup_entry(
async_add_entities(entities)
class ViCareSensor(SensorEntity):
class ViCareSensor(ViCareEntity, SensorEntity):
"""Representation of a ViCare sensor."""
_attr_has_entity_name = True
entity_description: ViCareSensorEntityDescription
def __init__(
self, name, api, device_config, description: ViCareSensorEntityDescription
self, name, api, device_config, description: ViCareSensorEntityDescription, hasMultipleDevices: bool
) -> None:
"""Initialize the sensor."""
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=f"{self._device_config.getModel()}-{self._device_config.getConfig().serial}",
manufacturer="Viessmann",
model=self._device_config.getModel(),
configuration_url="https://developer.viessmann.com/",
)
ViCareEntity.__init__(self, device_config, hasMultipleDevices)
@property
def available(self):