Skip to content

Commit

Permalink
Fixed control error entity (reading from trouble codes now), maybe fi…
Browse files Browse the repository at this point in the history
…xed an error with reading trouble codes from the API, setting manufacturer info from the brand on entities
  • Loading branch information
signalkraft committed Oct 8, 2023
1 parent 3a7307d commit 1d2b220
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ repos:
- aioresponses
- pytest
- types-requests
- myPyllant==0.5.7
- myPyllant==0.5.8
- polyfactory
- repo: local
hooks:
Expand Down
56 changes: 52 additions & 4 deletions custom_components/mypyllant/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import logging
from collections.abc import Mapping
from typing import Any

from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
Expand Down Expand Up @@ -33,6 +35,7 @@ async def async_setup_entry(

sensors: list[BinarySensorEntity] = []
for index, system in enumerate(coordinator.data):
sensors.append(ClaimEntity(index, coordinator))
sensors.append(ControlError(index, coordinator))
sensors.append(ControlOnline(index, coordinator))
sensors.append(FirmwareUpdateRequired(index, coordinator))
Expand All @@ -42,6 +45,45 @@ async def async_setup_entry(
async_add_entities(sensors)


class ClaimEntity(CoordinatorEntity, BinarySensorEntity):
def __init__(
self,
system_index: int,
coordinator: SystemCoordinator,
):
super().__init__(coordinator)
self.system_index = system_index

@property
def system(self) -> System:
return self.coordinator.data[self.system_index]

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC

@property
def extra_state_attributes(self) -> Mapping[str, Any] | None:
attr = {
"firmware": self.system.claim.firmware,
}
return attr

@property
def device_info(self):
return DeviceInfo(
identifiers={(DOMAIN, f"claim{self.system.id}")},
name=self.system.claim.nomenclature,
manufacturer=self.system.brand_name,
model=self.system.claim.nomenclature,
sw_version=self.system.claim.firmware_version,
)

@property
def name(self) -> str:
return self.system.claim.name


class SystemControlEntity(CoordinatorEntity, BinarySensorEntity):
def __init__(
self,
Expand Down Expand Up @@ -96,7 +138,7 @@ def device_info(self) -> DeviceInfo | None:
return DeviceInfo(
identifiers={(DOMAIN, f"circuit{self.circuit.index}")},
name=self.circuit_name,
manufacturer="Vaillant",
manufacturer=self.system.brand_name,
)


Expand All @@ -109,14 +151,20 @@ def __init__(
super().__init__(system_index, coordinator)
self.entity_id = f"{DOMAIN}.control_error_{system_index}"

@property
def extra_state_attributes(self) -> Mapping[str, Any] | None:
attr = {
"diagnostic_trouble_codes": self.system.diagnostic_trouble_codes,
}
return attr

@property
def is_on(self) -> bool | None:
# TODO: Find replacement
return False
return self.system.has_diagnostic_trouble_codes

@property
def name(self) -> str:
return f"Error {self.system.system_name}"
return f"Trouble Codes on {self.system.system_name}"

@property
def unique_id(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mypyllant/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def device_info(self) -> DeviceInfo:
return DeviceInfo(
identifiers={(DOMAIN, f"zone{self.zone.index}")},
name=self.name,
manufacturer="Vaillant",
manufacturer=self.system.brand_name,
)

@property
Expand Down
4 changes: 2 additions & 2 deletions custom_components/mypyllant/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"integration_type": "hub",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/signalkraft/issues",
"requirements": ["myPyllant==0.5.7"],
"version": "0.5.1"
"requirements": ["myPyllant==0.5.8"],
"version": "0.5.2b0"
}
2 changes: 1 addition & 1 deletion custom_components/mypyllant/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def device_info(self):
return DeviceInfo(
identifiers={(DOMAIN, f"device{self.device.device_uuid}")},
name=self.device.name_display,
manufacturer="Vaillant",
manufacturer=self.device.brand_name,
model=self.device.product_name_display,
)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/mypyllant/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def device_info(self) -> DeviceInfo:
(DOMAIN, f"domestic_hot_water{self.domestic_hot_water.index}")
},
name=self.name,
manufacturer="Vaillant",
manufacturer=self.system.brand_name,
)

@property
Expand Down
2 changes: 1 addition & 1 deletion requirements.test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
myPyllant==0.5.7
myPyllant==0.5.8
aioresponses==0.7.4
coverage>=6.3.1
croniter>=1.3.8
Expand Down
8 changes: 8 additions & 0 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from custom_components.mypyllant.binary_sensor import (
CircuitEntity,
CircuitIsCoolingAllowed,
ClaimEntity,
ControlError,
ControlOnline,
SystemControlEntity,
Expand All @@ -23,6 +24,13 @@ async def test_system_binary_sensors(
system = SystemControlEntity(0, system_coordinator_mock)
assert isinstance(system.device_info, dict)

system = ClaimEntity(0, system_coordinator_mock)
assert isinstance(system.device_info, dict)
assert (
system.extra_state_attributes
and "firmware" in system.extra_state_attributes
)

circuit = CircuitEntity(0, 0, system_coordinator_mock)
assert isinstance(circuit.device_info, dict)
assert isinstance(circuit.system, System)
Expand Down

0 comments on commit 1d2b220

Please sign in to comment.