Skip to content

Commit

Permalink
Fix units Trox TVE
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknn committed Dec 14, 2024
1 parent 64703e8 commit ba1830f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
3 changes: 1 addition & 2 deletions custom_components/modbus_tcpip/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async def initialize(self) -> None:
device_class = await load_device_class(self.device_model)
if device_class is not None:
self._modbusDevice = device_class(self.ip, self.port, self.slave_id)
await self._modbusDevice.readData()

@property
def device_id(self):
Expand Down Expand Up @@ -115,8 +116,6 @@ def registerOnUpdateCallback(self, entity, callbackfunc):
self._update_callbacks.update({entity: callbackfunc})

async def config_select(self, key, value):
_LOGGER.debug("Selected: %s %s", key, value)

self.config_selection = value
try:
await self._modbusDevice.readValue(ModbusDefaultGroups.CONFIG, key)
Expand Down
22 changes: 12 additions & 10 deletions custom_components/modbus_tcpip/devices/Swegon/CASA_R4.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, host:str, port:int, slave_id:int):
"Travelling Mode Speed Drop": ModbusDatapoint(Address=5105, DataType=ModbusNumberData(units=PERCENTAGE, min_value=0, max_value=20, step=1)),
"Fireplace Run Time": ModbusDatapoint(Address=5103, DataType=ModbusNumberData(units=UnitOfTime.MINUTES, min_value=0, max_value=60, step=1)),
"Fireplace Max Speed Difference": ModbusDatapoint(Address=5104, DataType=ModbusNumberData(units=PERCENTAGE, min_value=0, max_value=25, step=1)),
"Night Cooling": ModbusDatapoint(Address=5163),
"Night Cooling": ModbusDatapoint(Address=5163, DataType=ModbusNumberData(units=None)),
"Night Cooling FreshAir Max": ModbusDatapoint(Address=5164, Scaling=0.1, DataType=ModbusNumberData(deviceClass=NumberDeviceClass.TEMPERATURE, units=UnitOfTemperature.CELSIUS, min_value=0, max_value=25, step=0.1)),
"Night Cooling FreshAir Start": ModbusDatapoint(Address=5165, Scaling=0.1, DataType=ModbusNumberData(deviceClass=NumberDeviceClass.TEMPERATURE, units=UnitOfTemperature.CELSIUS, min_value=0, max_value=25, step=0.1)),
"Night Cooling RoomTemp Start": ModbusDatapoint(Address=5166, Scaling=0.1, DataType=ModbusNumberData(deviceClass=NumberDeviceClass.TEMPERATURE, units=UnitOfTemperature.CELSIUS, min_value=0, max_value=35, step=0.1)),
Expand All @@ -153,22 +153,23 @@ def __init__(self, host:str, port:int, slave_id:int):
"Boost Exhaust Speed": ModbusDatapoint(Address=5306, DataType=ModbusNumberData(units=PERCENTAGE, min_value=20, max_value=100, step=1)),
}

# CONFIGURATION - Read/Write
# UI datapoints that are calculated and not read directly over modbus
self.Datapoints[self.GROUP_UI] = {
"Efficiency": ModbusDatapoint(DataType=ModbusSensorData(units=PERCENTAGE)),
}

_LOGGER.debug("Loaded datapoints for %s %s", self.manufacturer, self.model)

async def onAfterRead(self):
# Update device info
self.model = self.Datapoints[self.GROUP_DEVICE_INFO]["Model Name"].Value
self.serial_number = self.Datapoints[self.GROUP_DEVICE_INFO]["Serial Number"].Value
if self.firstRead:
# Update device info
self.model = self.Datapoints[self.GROUP_DEVICE_INFO]["Model Name"].Value
self.serial_number = self.Datapoints[self.GROUP_DEVICE_INFO]["Serial Number"].Value

a = self.Datapoints[self.GROUP_DEVICE_INFO]["FW Maj"].Value
b = self.Datapoints[self.GROUP_DEVICE_INFO]["FW Min"].Value
c = self.Datapoints[self.GROUP_DEVICE_INFO]["FW Build"].Value
self.sw_version = '{}.{}.{}'.format(a,b,c)
a = self.Datapoints[self.GROUP_DEVICE_INFO]["FW Maj"].Value
b = self.Datapoints[self.GROUP_DEVICE_INFO]["FW Min"].Value
c = self.Datapoints[self.GROUP_DEVICE_INFO]["FW Build"].Value
self.sw_version = '{}.{}.{}'.format(a,b,c)

# Calculate efficiency
fresh = self.Datapoints[self.GROUP_SENSORS]["Fresh Air Temp"].Value
Expand All @@ -181,7 +182,8 @@ async def onAfterRead(self):
except ZeroDivisionError:
self.Datapoints[self.GROUP_UI]["Efficiency"].Value = 0

# Set alarms as attributes on Alarm-datapoint
# Set alarms as attributes on Alarm-datapoint. This is done so that we don't
# need to present all values in the UI
alarms = self.Datapoints[self.GROUP_ALARMS]
attrs = {}
for (dataPointName, data) in alarms.items():
Expand Down
14 changes: 7 additions & 7 deletions custom_components/modbus_tcpip/devices/Trox/TVE.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ def __init__(self, host:str, port:int, slave_id:int):
async def onBeforeRead(self):
# We need to adjust scaling of flow values depending on a configuration value
if self.firstRead:
scaling = 1
flowUnits = UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR
match await self.readValue(ModbusDefaultGroups.CONFIG, "201 Volume Flow Unit"):
case 0:
scaling = 3.6
flowUnits = "l/s"
case 1:
scaling = 1
flowUnits = UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR
case 6:
scaling = 1.69901
self.Datapoints[self.GROUP_0]["Flowrate Actual"].Scaling = scaling
self.Datapoints[ModbusDefaultGroups.CONFIG]["120 Q Min"].Scaling = scaling
self.Datapoints[ModbusDefaultGroups.CONFIG]["121 Q Max"].Scaling = scaling
flowUnits = UnitOfVolumeFlowRate.CUBIC_FEET_PER_MINUTE
self.Datapoints[self.GROUP_0]["Flowrate Actual"].DataType.units = flowUnits
self.Datapoints[ModbusDefaultGroups.CONFIG]["120 Q Min"].DataType.units = flowUnits
self.Datapoints[ModbusDefaultGroups.CONFIG]["121 Q Max"].DataType.units = flowUnits

async def onAfterRead(self):
self.sw_version = self.Datapoints[self.GROUP_DEVICE_INFO]["FW"].Value
Expand Down
3 changes: 1 addition & 2 deletions custom_components/modbus_tcpip/devices/modbusdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ async def readData(self):
await self.readGroup(group)
elif group.poll_mode == ModbusPollMode.POLL_ONCE and self.firstRead:
await self.readGroup(group)

self.firstRead = False

await self.onAfterRead()
self.firstRead = False

""" ******************************************************* """
""" ******************** READ GROUP *********************** """
Expand Down
1 change: 0 additions & 1 deletion custom_components/modbus_tcpip/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ async def async_select_option(self, option):
_LOGGER.debug("Select: %s", self._key)
try:
if self._key == "Config Selection":
_LOGGER.debug("Selecting")
await self.coordinator.config_select(option, value)
else:
_LOGGER.debug("Writing")
Expand Down

0 comments on commit ba1830f

Please sign in to comment.