mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
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
@ -112,61 +112,36 @@ def _build_entities(
|
|||||||
|
|
||||||
entities: list[ViCareBinarySensor] = []
|
entities: list[ViCareBinarySensor] = []
|
||||||
for device in device_list:
|
for device in device_list:
|
||||||
entities.extend(_build_entities_for_device(device.api, device.config))
|
# add device entities
|
||||||
entities.extend(
|
entities.extend(
|
||||||
_build_entities_for_component(
|
ViCareBinarySensor(
|
||||||
get_circuits(device.api), device.config, CIRCUIT_SENSORS
|
description,
|
||||||
|
device.config,
|
||||||
|
device.api,
|
||||||
)
|
)
|
||||||
|
for description in GLOBAL_SENSORS
|
||||||
|
if is_supported(description.key, description, device.api)
|
||||||
)
|
)
|
||||||
entities.extend(
|
# add component entities
|
||||||
_build_entities_for_component(
|
for component_list, entity_description_list in (
|
||||||
get_burners(device.api), device.config, BURNER_SENSORS
|
(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
|
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(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
@ -190,12 +165,13 @@ class ViCareBinarySensor(ViCareEntity, BinarySensorEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
device_config: PyViCareDeviceConfig,
|
|
||||||
api: PyViCareDevice | PyViCareHeatingDeviceComponent,
|
|
||||||
description: ViCareBinarySensorEntityDescription,
|
description: ViCareBinarySensorEntityDescription,
|
||||||
|
device_config: PyViCareDeviceConfig,
|
||||||
|
device: PyViCareDevice,
|
||||||
|
component: PyViCareHeatingDeviceComponent | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(device_config, api, description.key)
|
super().__init__(description.key, device_config, device, component)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -54,9 +54,9 @@ def _build_entities(
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
ViCareButton(
|
ViCareButton(
|
||||||
|
description,
|
||||||
device.config,
|
device.config,
|
||||||
device.api,
|
device.api,
|
||||||
description,
|
|
||||||
)
|
)
|
||||||
for device in device_list
|
for device in device_list
|
||||||
for description in BUTTON_DESCRIPTIONS
|
for description in BUTTON_DESCRIPTIONS
|
||||||
@ -87,12 +87,12 @@ class ViCareButton(ViCareEntity, ButtonEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
description: ViCareButtonEntityDescription,
|
||||||
device_config: PyViCareDeviceConfig,
|
device_config: PyViCareDeviceConfig,
|
||||||
device: PyViCareDevice,
|
device: PyViCareDevice,
|
||||||
description: ViCareButtonEntityDescription,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the button."""
|
"""Initialize the button."""
|
||||||
super().__init__(device_config, device, description.key)
|
super().__init__(description.key, device_config, device)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
def press(self) -> None:
|
def press(self) -> None:
|
||||||
|
@ -148,7 +148,7 @@ class ViCareClimate(ViCareEntity, ClimateEntity):
|
|||||||
circuit: PyViCareHeatingCircuit,
|
circuit: PyViCareHeatingCircuit,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the climate device."""
|
"""Initialize the climate device."""
|
||||||
super().__init__(device_config, device, circuit.id)
|
super().__init__(circuit.id, device_config, device)
|
||||||
self._circuit = circuit
|
self._circuit = circuit
|
||||||
self._attributes: dict[str, Any] = {}
|
self._attributes: dict[str, Any] = {}
|
||||||
self._attributes["vicare_programs"] = self._circuit.getPrograms()
|
self._attributes["vicare_programs"] = self._circuit.getPrograms()
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
from PyViCare.PyViCareDevice import Device as PyViCareDevice
|
from PyViCare.PyViCareDevice import Device as PyViCareDevice
|
||||||
from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig
|
from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig
|
||||||
|
from PyViCare.PyViCareHeatingDevice import (
|
||||||
|
HeatingDeviceWithComponent as PyViCareHeatingDeviceComponent,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
@ -16,21 +19,24 @@ class ViCareEntity(Entity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
unique_id_suffix: str,
|
||||||
device_config: PyViCareDeviceConfig,
|
device_config: PyViCareDeviceConfig,
|
||||||
device: PyViCareDevice,
|
device: PyViCareDevice,
|
||||||
unique_id_suffix: str,
|
component: PyViCareHeatingDeviceComponent | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the entity."""
|
"""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}"
|
self._attr_unique_id = f"{device_config.getConfig().serial}-{unique_id_suffix}"
|
||||||
# valid for compressors, circuits, burners (HeatingDeviceWithComponent)
|
# valid for compressors, circuits, burners (HeatingDeviceWithComponent)
|
||||||
if hasattr(device, "id"):
|
if component:
|
||||||
self._attr_unique_id += f"-{device.id}"
|
self._attr_unique_id += f"-{component.id}"
|
||||||
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, device_config.getConfig().serial)},
|
identifiers={(DOMAIN, device_config.getConfig().serial)},
|
||||||
serial_number=device_config.getConfig().serial,
|
serial_number=device.getSerial(),
|
||||||
name=device_config.getModel(),
|
name=device_config.getModel(),
|
||||||
manufacturer="Viessmann",
|
manufacturer="Viessmann",
|
||||||
model=device_config.getModel(),
|
model=device_config.getModel(),
|
||||||
|
@ -129,7 +129,7 @@ class ViCareFan(ViCareEntity, FanEntity):
|
|||||||
device: PyViCareDevice,
|
device: PyViCareDevice,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the fan entity."""
|
"""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:
|
def update(self) -> None:
|
||||||
"""Update state of fan."""
|
"""Update state of fan."""
|
||||||
|
@ -245,30 +245,30 @@ def _build_entities(
|
|||||||
) -> list[ViCareNumber]:
|
) -> list[ViCareNumber]:
|
||||||
"""Create ViCare number entities for a device."""
|
"""Create ViCare number entities for a device."""
|
||||||
|
|
||||||
entities: list[ViCareNumber] = [
|
entities: list[ViCareNumber] = []
|
||||||
ViCareNumber(
|
for device in device_list:
|
||||||
device.config,
|
# add device entities
|
||||||
device.api,
|
entities.extend(
|
||||||
description,
|
|
||||||
)
|
|
||||||
for device in device_list
|
|
||||||
for description in DEVICE_ENTITY_DESCRIPTIONS
|
|
||||||
if is_supported(description.key, description, device.api)
|
|
||||||
]
|
|
||||||
|
|
||||||
entities.extend(
|
|
||||||
[
|
|
||||||
ViCareNumber(
|
ViCareNumber(
|
||||||
device.config,
|
|
||||||
circuit,
|
|
||||||
description,
|
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 circuit in get_circuits(device.api)
|
||||||
for description in CIRCUIT_ENTITY_DESCRIPTIONS
|
for description in CIRCUIT_ENTITY_DESCRIPTIONS
|
||||||
if is_supported(description.key, description, circuit)
|
if is_supported(description.key, description, circuit)
|
||||||
]
|
)
|
||||||
)
|
|
||||||
return entities
|
return entities
|
||||||
|
|
||||||
|
|
||||||
@ -295,12 +295,13 @@ class ViCareNumber(ViCareEntity, NumberEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
device_config: PyViCareDeviceConfig,
|
|
||||||
api: PyViCareDevice | PyViCareHeatingDeviceComponent,
|
|
||||||
description: ViCareNumberEntityDescription,
|
description: ViCareNumberEntityDescription,
|
||||||
|
device_config: PyViCareDeviceConfig,
|
||||||
|
device: PyViCareDevice,
|
||||||
|
component: PyViCareHeatingDeviceComponent | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the number."""
|
"""Initialize the number."""
|
||||||
super().__init__(device_config, api, description.key)
|
super().__init__(description.key, device_config, device, component)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -747,7 +747,6 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
CIRCUIT_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
CIRCUIT_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
||||||
ViCareSensorEntityDescription(
|
ViCareSensorEntityDescription(
|
||||||
key="supply_temperature",
|
key="supply_temperature",
|
||||||
@ -865,61 +864,36 @@ def _build_entities(
|
|||||||
|
|
||||||
entities: list[ViCareSensor] = []
|
entities: list[ViCareSensor] = []
|
||||||
for device in device_list:
|
for device in device_list:
|
||||||
entities.extend(_build_entities_for_device(device.api, device.config))
|
# add device entities
|
||||||
entities.extend(
|
entities.extend(
|
||||||
_build_entities_for_component(
|
ViCareSensor(
|
||||||
get_circuits(device.api), device.config, CIRCUIT_SENSORS
|
description,
|
||||||
|
device.config,
|
||||||
|
device.api,
|
||||||
)
|
)
|
||||||
|
for description in GLOBAL_SENSORS
|
||||||
|
if is_supported(description.key, description, device.api)
|
||||||
)
|
)
|
||||||
entities.extend(
|
# add component entities
|
||||||
_build_entities_for_component(
|
for component_list, entity_description_list in (
|
||||||
get_burners(device.api), device.config, BURNER_SENSORS
|
(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
|
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(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
@ -945,12 +919,13 @@ class ViCareSensor(ViCareEntity, SensorEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
device_config: PyViCareDeviceConfig,
|
|
||||||
api: PyViCareDevice | PyViCareHeatingDeviceComponent,
|
|
||||||
description: ViCareSensorEntityDescription,
|
description: ViCareSensorEntityDescription,
|
||||||
|
device_config: PyViCareDeviceConfig,
|
||||||
|
device: PyViCareDevice,
|
||||||
|
component: PyViCareHeatingDeviceComponent | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(device_config, api, description.key)
|
super().__init__(description.key, device_config, device, component)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -113,7 +113,7 @@ class ViCareWater(ViCareEntity, WaterHeaterEntity):
|
|||||||
circuit: PyViCareHeatingCircuit,
|
circuit: PyViCareHeatingCircuit,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the DHW water_heater device."""
|
"""Initialize the DHW water_heater device."""
|
||||||
super().__init__(device_config, device, circuit.id)
|
super().__init__(circuit.id, device_config, device)
|
||||||
self._circuit = circuit
|
self._circuit = circuit
|
||||||
self._attributes: dict[str, Any] = {}
|
self._attributes: dict[str, Any] = {}
|
||||||
|
|
||||||
|
@ -1,5 +1,22 @@
|
|||||||
{
|
{
|
||||||
"data": [
|
"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": {},
|
"properties": {},
|
||||||
"commands": {},
|
"commands": {},
|
||||||
|
@ -4,6 +4,24 @@
|
|||||||
'data': list([
|
'data': list([
|
||||||
dict({
|
dict({
|
||||||
'data': list([
|
'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({
|
dict({
|
||||||
'apiVersion': 1,
|
'apiVersion': 1,
|
||||||
'commands': dict({
|
'commands': dict({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user