Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #24

Merged
merged 5 commits into from
May 1, 2024
Merged

Dev #24

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions custom_components/dantherm/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ class DanthermNumberEntityDescription(NumberEntityDescription):
"""Dantherm Number Entity Description."""

data_setaddress: int | None = None
data_setinternal: str | None = None
data_setclass: DataClass | None = None

data_address: int | None = None
data_getinternal: str | None = None
data_entity: str | None = None
data_exclude_if: Any | None = None
data_class: DataClass = DataClass.UInt16
Expand Down Expand Up @@ -224,8 +226,8 @@ class DanthermSwitchEntityDescription(SwitchEntityDescription):
NUMBER_TYPES: dict[str, list[DanthermNumberEntityDescription]] = {
"filter_lifetime": DanthermNumberEntityDescription(
key="filter_lifetime",
data_class=DataClass.UInt32,
data_address=556,
data_setinternal="set_filter_lifetime",
data_getinternal="get_filter_lifetime",
native_max_value=360,
native_min_value=0,
device_class=NumberDeviceClass.DURATION,
Expand Down Expand Up @@ -351,8 +353,7 @@ class DanthermSwitchEntityDescription(SwitchEntityDescription):
),
"filter_remain": DanthermSensorEntityDescription(
key="filter_remain",
data_class=DataClass.UInt32,
data_address=554,
data_getinternal="get_filter_remain",
native_unit_of_measurement="d",
device_class=SensorDeviceClass.DURATION,
state_class=SensorStateClass.MEASUREMENT,
Expand Down Expand Up @@ -412,7 +413,7 @@ class DanthermSwitchEntityDescription(SwitchEntityDescription):
state_suspend_for=30,
state_on=0x800,
icon_on="mdi:emoticon-cool-outline",
state_off=8800,
state_off=0x8800,
icon_off="mdi:power-off",
device_class=SwitchDeviceClass.SWITCH,
),
Expand Down
33 changes: 33 additions & 0 deletions custom_components/dantherm/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def __init__(
self._active_unit_mode = 0
self._fan_level = 0
self._alarm = 0
self._filter_lifetime = 0
self._filter_remain = 0
self._entities = []
self.data = {}

Expand Down Expand Up @@ -213,6 +215,12 @@ async def async_refresh_entities(self, _now: int | None = None) -> None:
self._alarm = await self._read_holding_uint32(516)
_LOGGER.debug("Alarm = %s", self._alarm)

self._filter_lifetime = await self._read_holding_uint32(556)
_LOGGER.debug("Filter lifetime = %s", self._filter_lifetime)

self._filter_remain = await self._read_holding_uint32(554)
_LOGGER.debug("Filter remain = %s", self._filter_remain)

for entity in self._entities:
await self.async_refresh_entity(entity)

Expand Down Expand Up @@ -287,6 +295,26 @@ def get_alarm(self):

return self._alarm

@property
def get_filter_lifetime(self):
"""Get filter lifetime."""

return self._filter_lifetime

@property
def get_filter_remain(self):
"""Get filter remain."""

return self._filter_remain

@property
def get_filter_remain_attrs(self):
"""Get filter remain attributes."""

if not self._filter_lifetime:
return None
return {"level": int(self._filter_remain / (self._filter_lifetime / 4))}

async def set_active_unit_mode(self, value):
"""Set active unit mode."""

Expand All @@ -309,6 +337,11 @@ async def set_fan_level(self, value):

await self._write_holding_uint32(324, value)

async def set_filter_lifetime(self, value):
"""Set filter lifetime."""

await self._write_holding_uint32(556, value)

async def set_bypass_damper(self, feature: CoverEntityFeature = None):
"""Set bypass damper."""

Expand Down
23 changes: 19 additions & 4 deletions custom_components/dantherm/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,27 @@ def native_value(self):
async def async_set_native_value(self, value: int) -> None:
"""Update the current value."""

await self._device.write_holding_registers(description=self.entity_description)
if self.entity_description.data_setinternal:
await getattr(self._device, self.entity_description.data_setinternal)(value)
else:
await self._device.write_holding_registers(
description=self.entity_description
)

async def async_update(self) -> None:
"""Read holding register."""

result = await self._device.read_holding_registers(
description=self.entity_description
)
if self.entity_description.data_getinternal:
if hasattr(
self._device, f"{self.entity_description.data_getinternal}_attrs"
):
self._attr_extra_state_attributes = getattr(
self._device,
f"{self.entity_description.data_getinternal}_attrs",
)
result = getattr(self._device, self.entity_description.data_getinternal)
else:
result = await self._device.read_holding_registers(
description=self.entity_description
)
self._device.data[self.key] = result
7 changes: 7 additions & 0 deletions custom_components/dantherm/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ async def async_update(self) -> None:
"""Read holding register."""

if self.entity_description.data_getinternal:
if hasattr(
self._device, f"{self.entity_description.data_getinternal}_attrs"
):
self._attr_extra_state_attributes = getattr(
self._device,
f"{self.entity_description.data_getinternal}_attrs",
)
result = getattr(self._device, self.entity_description.data_getinternal)
elif self.entity_description.data_entity:
result = self._device.data.get(self.entity_description.data_entity, None)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/dantherm/translations/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"3": "Ugeprogram tilstand",
"4": "Servoflow",
"5": "Bortrejst tilstand",
"6": "Sommer tilstand",
"6": "Sommertilstand",
"7": "DI tilsidesættelse",
"8": "Hygrostat tilsidesættelse",
"9": "Brændeovnstilstand",
Expand Down Expand Up @@ -125,7 +125,7 @@
"night_mode": { "name": "Nattilstand" },
"fireplace_mode": { "name": "Brændeovnstilstand" },
"manual_bypass_mode": { "name": "Manuel bypasstilstand" },
"summer_mode": { "name": "Summer tilstand" }
"summer_mode": { "name": "Sommertilstand" }
}
}
}
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Dantherm",
"zip_release": true,
"hide_default_branch": true,
"hide_default_branch": false,
"filename": "dantherm.zip",
"render_readme": true,
"content_in_root": false
Expand Down
37 changes: 37 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[![GitHub Release][releases-shield]][releases]
[![GitHub Activity][commits-shield]][commits]
[![License][license-shield]][license]

[![hacs][hacsbadge]][hacs]
[![Project Maintenance][maintenance-shield]][user_profile]

Platform | Description
:---: | :---
Select | Operation mode
Select | Fan level
Select | Week program[^1]
Cover | Bypass damper[^1]
Number | Filter lifetime
Sensor | Operation mode
Sensor | Alarm
Sensor | Fan level
Sensor | Fan speed 1[^2]
Sensor | Fan speed 2[^2]
Sensor | Humidity[^1][^3]
Sensor | Air quality[^1][^3]
Sensor | Exhaust temperature
Sensor | Extract temperature
Sensor | Supply temperature
Sensor | Outdoor temperature
Sensor | Filter ramaining time
Switch | Away mode
Switch | Night mode
Switch | Fireplace mode
Switch | Manual bypass mode[^1]
Switch | Summer mode

[^1] The installation of the entity relies on the support or installation within the specific ventilation unit.

[^2] Fan speeds 1 and 2 is the fan speed for either the extract or supply side of the heat exchanger, with the specific side varying across the different models.

[^3] The humidity and air quality is measured in the extract side of the unit.
Loading