Correct device serial for ViCare integration (#125125)
* expose correct serial * adapt inits * adjust _build_entities * adapt inits * add serial data point * update snapshot * apply suggestions * apply suggestions
This commit is contained in:
parent
fc24843274
commit
f34b449f61
10 changed files with 128 additions and 135 deletions
|
@ -112,61 +112,36 @@ def _build_entities(
|
|||
|
||||
entities: list[ViCareBinarySensor] = []
|
||||
for device in device_list:
|
||||
entities.extend(_build_entities_for_device(device.api, device.config))
|
||||
# add device entities
|
||||
entities.extend(
|
||||
_build_entities_for_component(
|
||||
get_circuits(device.api), device.config, CIRCUIT_SENSORS
|
||||
ViCareBinarySensor(
|
||||
description,
|
||||
device.config,
|
||||
device.api,
|
||||
)
|
||||
for description in GLOBAL_SENSORS
|
||||
if is_supported(description.key, description, device.api)
|
||||
)
|
||||
entities.extend(
|
||||
_build_entities_for_component(
|
||||
get_burners(device.api), device.config, BURNER_SENSORS
|
||||
# add component entities
|
||||
for component_list, entity_description_list in (
|
||||
(get_circuits(device.api), CIRCUIT_SENSORS),
|
||||
(get_burners(device.api), BURNER_SENSORS),
|
||||
(get_compressors(device.api), COMPRESSOR_SENSORS),
|
||||
):
|
||||
entities.extend(
|
||||
ViCareBinarySensor(
|
||||
description,
|
||||
device.config,
|
||||
device.api,
|
||||
component,
|
||||
)
|
||||
for component in component_list
|
||||
for description in entity_description_list
|
||||
if is_supported(description.key, description, component)
|
||||
)
|
||||
)
|
||||
entities.extend(
|
||||
_build_entities_for_component(
|
||||
get_compressors(device.api), device.config, COMPRESSOR_SENSORS
|
||||
)
|
||||
)
|
||||
return entities
|
||||
|
||||
|
||||
def _build_entities_for_device(
|
||||
device: PyViCareDevice,
|
||||
device_config: PyViCareDeviceConfig,
|
||||
) -> list[ViCareBinarySensor]:
|
||||
"""Create device specific ViCare binary sensor entities."""
|
||||
|
||||
return [
|
||||
ViCareBinarySensor(
|
||||
device_config,
|
||||
device,
|
||||
description,
|
||||
)
|
||||
for description in GLOBAL_SENSORS
|
||||
if is_supported(description.key, description, device)
|
||||
]
|
||||
|
||||
|
||||
def _build_entities_for_component(
|
||||
components: list[PyViCareHeatingDeviceComponent],
|
||||
device_config: PyViCareDeviceConfig,
|
||||
entity_descriptions: tuple[ViCareBinarySensorEntityDescription, ...],
|
||||
) -> list[ViCareBinarySensor]:
|
||||
"""Create component specific ViCare binary sensor entities."""
|
||||
|
||||
return [
|
||||
ViCareBinarySensor(
|
||||
device_config,
|
||||
component,
|
||||
description,
|
||||
)
|
||||
for component in components
|
||||
for description in entity_descriptions
|
||||
if is_supported(description.key, description, component)
|
||||
]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
|
@ -190,12 +165,13 @@ class ViCareBinarySensor(ViCareEntity, BinarySensorEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
device_config: PyViCareDeviceConfig,
|
||||
api: PyViCareDevice | PyViCareHeatingDeviceComponent,
|
||||
description: ViCareBinarySensorEntityDescription,
|
||||
device_config: PyViCareDeviceConfig,
|
||||
device: PyViCareDevice,
|
||||
component: PyViCareHeatingDeviceComponent | None = None,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(device_config, api, description.key)
|
||||
super().__init__(description.key, device_config, device, component)
|
||||
self.entity_description = description
|
||||
|
||||
@property
|
||||
|
|
|
@ -54,9 +54,9 @@ def _build_entities(
|
|||
|
||||
return [
|
||||
ViCareButton(
|
||||
description,
|
||||
device.config,
|
||||
device.api,
|
||||
description,
|
||||
)
|
||||
for device in device_list
|
||||
for description in BUTTON_DESCRIPTIONS
|
||||
|
@ -87,12 +87,12 @@ class ViCareButton(ViCareEntity, ButtonEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
description: ViCareButtonEntityDescription,
|
||||
device_config: PyViCareDeviceConfig,
|
||||
device: PyViCareDevice,
|
||||
description: ViCareButtonEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the button."""
|
||||
super().__init__(device_config, device, description.key)
|
||||
super().__init__(description.key, device_config, device)
|
||||
self.entity_description = description
|
||||
|
||||
def press(self) -> None:
|
||||
|
|
|
@ -148,7 +148,7 @@ class ViCareClimate(ViCareEntity, ClimateEntity):
|
|||
circuit: PyViCareHeatingCircuit,
|
||||
) -> None:
|
||||
"""Initialize the climate device."""
|
||||
super().__init__(device_config, device, circuit.id)
|
||||
super().__init__(circuit.id, device_config, device)
|
||||
self._circuit = circuit
|
||||
self._attributes: dict[str, Any] = {}
|
||||
self._attributes["vicare_programs"] = self._circuit.getPrograms()
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
from PyViCare.PyViCareDevice import Device as PyViCareDevice
|
||||
from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig
|
||||
from PyViCare.PyViCareHeatingDevice import (
|
||||
HeatingDeviceWithComponent as PyViCareHeatingDeviceComponent,
|
||||
)
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -16,21 +19,24 @@ class ViCareEntity(Entity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
unique_id_suffix: str,
|
||||
device_config: PyViCareDeviceConfig,
|
||||
device: PyViCareDevice,
|
||||
unique_id_suffix: str,
|
||||
component: PyViCareHeatingDeviceComponent | None = None,
|
||||
) -> None:
|
||||
"""Initialize the entity."""
|
||||
self._api = device
|
||||
self._api: PyViCareDevice | PyViCareHeatingDeviceComponent = (
|
||||
component if component else device
|
||||
)
|
||||
|
||||
self._attr_unique_id = f"{device_config.getConfig().serial}-{unique_id_suffix}"
|
||||
# valid for compressors, circuits, burners (HeatingDeviceWithComponent)
|
||||
if hasattr(device, "id"):
|
||||
self._attr_unique_id += f"-{device.id}"
|
||||
if component:
|
||||
self._attr_unique_id += f"-{component.id}"
|
||||
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device_config.getConfig().serial)},
|
||||
serial_number=device_config.getConfig().serial,
|
||||
serial_number=device.getSerial(),
|
||||
name=device_config.getModel(),
|
||||
manufacturer="Viessmann",
|
||||
model=device_config.getModel(),
|
||||
|
|
|
@ -129,7 +129,7 @@ class ViCareFan(ViCareEntity, FanEntity):
|
|||
device: PyViCareDevice,
|
||||
) -> None:
|
||||
"""Initialize the fan entity."""
|
||||
super().__init__(device_config, device, self._attr_translation_key)
|
||||
super().__init__(self._attr_translation_key, device_config, device)
|
||||
|
||||
def update(self) -> None:
|
||||
"""Update state of fan."""
|
||||
|
|
|
@ -245,30 +245,30 @@ def _build_entities(
|
|||
) -> list[ViCareNumber]:
|
||||
"""Create ViCare number entities for a device."""
|
||||
|
||||
entities: list[ViCareNumber] = [
|
||||
ViCareNumber(
|
||||
device.config,
|
||||
device.api,
|
||||
description,
|
||||
)
|
||||
for device in device_list
|
||||
for description in DEVICE_ENTITY_DESCRIPTIONS
|
||||
if is_supported(description.key, description, device.api)
|
||||
]
|
||||
|
||||
entities.extend(
|
||||
[
|
||||
entities: list[ViCareNumber] = []
|
||||
for device in device_list:
|
||||
# add device entities
|
||||
entities.extend(
|
||||
ViCareNumber(
|
||||
device.config,
|
||||
circuit,
|
||||
description,
|
||||
device.config,
|
||||
device.api,
|
||||
)
|
||||
for description in DEVICE_ENTITY_DESCRIPTIONS
|
||||
if is_supported(description.key, description, device.api)
|
||||
)
|
||||
# add component entities
|
||||
entities.extend(
|
||||
ViCareNumber(
|
||||
description,
|
||||
device.config,
|
||||
device.api,
|
||||
circuit,
|
||||
)
|
||||
for device in device_list
|
||||
for circuit in get_circuits(device.api)
|
||||
for description in CIRCUIT_ENTITY_DESCRIPTIONS
|
||||
if is_supported(description.key, description, circuit)
|
||||
]
|
||||
)
|
||||
)
|
||||
return entities
|
||||
|
||||
|
||||
|
@ -295,12 +295,13 @@ class ViCareNumber(ViCareEntity, NumberEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
device_config: PyViCareDeviceConfig,
|
||||
api: PyViCareDevice | PyViCareHeatingDeviceComponent,
|
||||
description: ViCareNumberEntityDescription,
|
||||
device_config: PyViCareDeviceConfig,
|
||||
device: PyViCareDevice,
|
||||
component: PyViCareHeatingDeviceComponent | None = None,
|
||||
) -> None:
|
||||
"""Initialize the number."""
|
||||
super().__init__(device_config, api, description.key)
|
||||
super().__init__(description.key, device_config, device, component)
|
||||
self.entity_description = description
|
||||
|
||||
@property
|
||||
|
|
|
@ -747,7 +747,6 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
|||
),
|
||||
)
|
||||
|
||||
|
||||
CIRCUIT_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
||||
ViCareSensorEntityDescription(
|
||||
key="supply_temperature",
|
||||
|
@ -865,61 +864,36 @@ def _build_entities(
|
|||
|
||||
entities: list[ViCareSensor] = []
|
||||
for device in device_list:
|
||||
entities.extend(_build_entities_for_device(device.api, device.config))
|
||||
# add device entities
|
||||
entities.extend(
|
||||
_build_entities_for_component(
|
||||
get_circuits(device.api), device.config, CIRCUIT_SENSORS
|
||||
ViCareSensor(
|
||||
description,
|
||||
device.config,
|
||||
device.api,
|
||||
)
|
||||
for description in GLOBAL_SENSORS
|
||||
if is_supported(description.key, description, device.api)
|
||||
)
|
||||
entities.extend(
|
||||
_build_entities_for_component(
|
||||
get_burners(device.api), device.config, BURNER_SENSORS
|
||||
# add component entities
|
||||
for component_list, entity_description_list in (
|
||||
(get_circuits(device.api), CIRCUIT_SENSORS),
|
||||
(get_burners(device.api), BURNER_SENSORS),
|
||||
(get_compressors(device.api), COMPRESSOR_SENSORS),
|
||||
):
|
||||
entities.extend(
|
||||
ViCareSensor(
|
||||
description,
|
||||
device.config,
|
||||
device.api,
|
||||
component,
|
||||
)
|
||||
for component in component_list
|
||||
for description in entity_description_list
|
||||
if is_supported(description.key, description, component)
|
||||
)
|
||||
)
|
||||
entities.extend(
|
||||
_build_entities_for_component(
|
||||
get_compressors(device.api), device.config, COMPRESSOR_SENSORS
|
||||
)
|
||||
)
|
||||
return entities
|
||||
|
||||
|
||||
def _build_entities_for_device(
|
||||
device: PyViCareDevice,
|
||||
device_config: PyViCareDeviceConfig,
|
||||
) -> list[ViCareSensor]:
|
||||
"""Create device specific ViCare sensor entities."""
|
||||
|
||||
return [
|
||||
ViCareSensor(
|
||||
device_config,
|
||||
device,
|
||||
description,
|
||||
)
|
||||
for description in GLOBAL_SENSORS
|
||||
if is_supported(description.key, description, device)
|
||||
]
|
||||
|
||||
|
||||
def _build_entities_for_component(
|
||||
components: list[PyViCareHeatingDeviceComponent],
|
||||
device_config: PyViCareDeviceConfig,
|
||||
entity_descriptions: tuple[ViCareSensorEntityDescription, ...],
|
||||
) -> list[ViCareSensor]:
|
||||
"""Create component specific ViCare sensor entities."""
|
||||
|
||||
return [
|
||||
ViCareSensor(
|
||||
device_config,
|
||||
component,
|
||||
description,
|
||||
)
|
||||
for component in components
|
||||
for description in entity_descriptions
|
||||
if is_supported(description.key, description, component)
|
||||
]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
|
@ -945,12 +919,13 @@ class ViCareSensor(ViCareEntity, SensorEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
device_config: PyViCareDeviceConfig,
|
||||
api: PyViCareDevice | PyViCareHeatingDeviceComponent,
|
||||
description: ViCareSensorEntityDescription,
|
||||
device_config: PyViCareDeviceConfig,
|
||||
device: PyViCareDevice,
|
||||
component: PyViCareHeatingDeviceComponent | None = None,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(device_config, api, description.key)
|
||||
super().__init__(description.key, device_config, device, component)
|
||||
self.entity_description = description
|
||||
|
||||
@property
|
||||
|
|
|
@ -113,7 +113,7 @@ class ViCareWater(ViCareEntity, WaterHeaterEntity):
|
|||
circuit: PyViCareHeatingCircuit,
|
||||
) -> None:
|
||||
"""Initialize the DHW water_heater device."""
|
||||
super().__init__(device_config, device, circuit.id)
|
||||
super().__init__(circuit.id, device_config, device)
|
||||
self._circuit = circuit
|
||||
self._attributes: dict[str, Any] = {}
|
||||
|
||||
|
|
|
@ -1,5 +1,22 @@
|
|||
{
|
||||
"data": [
|
||||
{
|
||||
"apiVersion": 1,
|
||||
"commands": {},
|
||||
"deviceId": "0",
|
||||
"feature": "device.serial",
|
||||
"gatewayId": "################",
|
||||
"isEnabled": true,
|
||||
"isReady": true,
|
||||
"properties": {
|
||||
"value": {
|
||||
"type": "string",
|
||||
"value": "################"
|
||||
}
|
||||
},
|
||||
"timestamp": "2024-03-20T01:29:35.549Z",
|
||||
"uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/0/features/device.serial"
|
||||
},
|
||||
{
|
||||
"properties": {},
|
||||
"commands": {},
|
||||
|
|
|
@ -4,6 +4,24 @@
|
|||
'data': list([
|
||||
dict({
|
||||
'data': list([
|
||||
dict({
|
||||
'apiVersion': 1,
|
||||
'commands': dict({
|
||||
}),
|
||||
'deviceId': '0',
|
||||
'feature': 'device.serial',
|
||||
'gatewayId': '################',
|
||||
'isEnabled': True,
|
||||
'isReady': True,
|
||||
'properties': dict({
|
||||
'value': dict({
|
||||
'type': 'string',
|
||||
'value': '################',
|
||||
}),
|
||||
}),
|
||||
'timestamp': '2024-03-20T01:29:35.549Z',
|
||||
'uri': 'https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/0/features/device.serial',
|
||||
}),
|
||||
dict({
|
||||
'apiVersion': 1,
|
||||
'commands': dict({
|
||||
|
|
Loading…
Add table
Reference in a new issue