Skip to content

Commit

Permalink
May have fixed restart HA issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Tvalley71 committed Apr 28, 2024
1 parent 4d6ddba commit 25dc32b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions custom_components/dantherm/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadBuilder, BinaryPayloadDecoder

from homeassistant.components.cover import CoverEntityFeature
from homeassistant.components.modbus import modbus
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity, EntityDescription
Expand Down Expand Up @@ -134,7 +135,11 @@ async def setup(self):
_LOGGER.error("Modbus setup was unsuccessful")
raise ValueError("Modbus setup was unsuccessful")

self._device_installed_components = await self._read_holding_uint16(610)
result = await self._read_holding_uint16(610)
if result is None:
raise ValueError("Dantherm unit probably not responding")

self._device_installed_components = result
_LOGGER.debug(
"Installed components (610) = %s",
hex(self._device_installed_components),
Expand Down Expand Up @@ -304,6 +309,14 @@ async def set_fan_level(self, value):

await self._write_holding_uint32(324, value)

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

if self.get_active_unit_mode & 0x80 == 0x80:
await self.set_active_unit_mode(0x8080)
else:
await self.set_active_unit_mode(0x80)

async def read_holding_registers(
self,
description: EntityDescription | None = None,
Expand Down Expand Up @@ -421,7 +434,7 @@ async def _read_holding_registers(self, address, count):
self._unit_id, address, count, "holding"
)
if result is None:
_LOGGER.log(
_LOGGER.error(
"Error reading holding register=%s count=%s", str(address), str(count)
)
return result
Expand All @@ -436,7 +449,7 @@ async def _write_holding_registers(self, address, values: list[int] | int):
"write_registers",
)
if result is None:
_LOGGER.log(
_LOGGER.error(
"Error writing holding register=%s values=%s", str(address), str(values)
)

Expand Down Expand Up @@ -495,6 +508,8 @@ async def _read_holding_uint16(self, address):
"""Read holding uint16 registers."""

result = await self._read_holding_registers(address, 1)
if result is None:
return None
decoder = BinaryPayloadDecoder.fromRegisters(
result.registers, byteorder=Endian.BIG, wordorder=Endian.LITTLE
)
Expand Down

0 comments on commit 25dc32b

Please sign in to comment.