mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 17:45:19 +02:00
Update sensor.py
This commit is contained in:
committed by
GitHub
parent
1bcc946256
commit
003faefb12
@@ -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."""
|
"""Create a ViCare sensor entity."""
|
||||||
_LOGGER.debug("Found device %s", name)
|
_LOGGER.debug("Found device %s", name)
|
||||||
try:
|
try:
|
||||||
@@ -593,11 +593,12 @@ def _build_entity(name, vicare_api, device_config, sensor):
|
|||||||
vicare_api,
|
vicare_api,
|
||||||
device_config,
|
device_config,
|
||||||
sensor,
|
sensor,
|
||||||
|
hasMultipleDevices,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _entities_from_descriptions(
|
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."""
|
"""Create entities from descriptions and list of burners/circuits."""
|
||||||
for description in sensor_descriptions:
|
for description in sensor_descriptions:
|
||||||
@@ -611,6 +612,7 @@ async def _entities_from_descriptions(
|
|||||||
current,
|
current,
|
||||||
device,
|
device,
|
||||||
description,
|
description,
|
||||||
|
hasMultipleDevices,
|
||||||
)
|
)
|
||||||
if entity is not None:
|
if entity is not None:
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
@@ -623,6 +625,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Create the ViCare sensor devices."""
|
"""Create the ViCare sensor devices."""
|
||||||
entities = []
|
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]:
|
for device in hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_LIST]:
|
||||||
api = getattr(
|
api = getattr(
|
||||||
@@ -638,27 +641,28 @@ async def async_setup_entry(
|
|||||||
api,
|
api,
|
||||||
device,
|
device,
|
||||||
description,
|
description,
|
||||||
|
hasMultipleDevices,
|
||||||
)
|
)
|
||||||
if entity is not None:
|
if entity is not None:
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await _entities_from_descriptions(
|
await _entities_from_descriptions(
|
||||||
hass, entities, CIRCUIT_SENSORS, api.circuits, device
|
hass, entities, CIRCUIT_SENSORS, api.circuits, device, hasMultipleDevices
|
||||||
)
|
)
|
||||||
except PyViCareNotSupportedFeatureError:
|
except PyViCareNotSupportedFeatureError:
|
||||||
_LOGGER.info("No circuits found")
|
_LOGGER.info("No circuits found")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await _entities_from_descriptions(
|
await _entities_from_descriptions(
|
||||||
hass, entities, BURNER_SENSORS, api.burners, device
|
hass, entities, BURNER_SENSORS, api.burners, device, hasMultipleDevices
|
||||||
)
|
)
|
||||||
except PyViCareNotSupportedFeatureError:
|
except PyViCareNotSupportedFeatureError:
|
||||||
_LOGGER.info("No burners found")
|
_LOGGER.info("No burners found")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await _entities_from_descriptions(
|
await _entities_from_descriptions(
|
||||||
hass, entities, COMPRESSOR_SENSORS, api.compressors, device
|
hass, entities, COMPRESSOR_SENSORS, api.compressors, device, hasMultipleDevices
|
||||||
)
|
)
|
||||||
except PyViCareNotSupportedFeatureError:
|
except PyViCareNotSupportedFeatureError:
|
||||||
_LOGGER.info("No compressors found")
|
_LOGGER.info("No compressors found")
|
||||||
@@ -666,31 +670,21 @@ async def async_setup_entry(
|
|||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class ViCareSensor(SensorEntity):
|
class ViCareSensor(ViCareEntity, SensorEntity):
|
||||||
"""Representation of a ViCare sensor."""
|
"""Representation of a ViCare sensor."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
entity_description: ViCareSensorEntityDescription
|
entity_description: ViCareSensorEntityDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, name, api, device_config, description: ViCareSensorEntityDescription
|
self, name, api, device_config, description: ViCareSensorEntityDescription, hasMultipleDevices: bool
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_name = name
|
self._attr_name = name
|
||||||
self._api = api
|
self._api = api
|
||||||
self._device_config = device_config
|
self._device_config = device_config
|
||||||
|
ViCareEntity.__init__(self, device_config, hasMultipleDevices)
|
||||||
@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/",
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
|
Reference in New Issue
Block a user