diff --git a/packages/modules/common/sdm.py b/packages/modules/common/sdm.py index 2e348bfdd1..f6af11163d 100644 --- a/packages/modules/common/sdm.py +++ b/packages/modules/common/sdm.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 from enum import IntEnum +import time +from typing import List, Tuple from modules.common import modbus from modules.common.abstract_counter import AbstractCounter @@ -16,6 +18,11 @@ def __init__(self, modbus_id: int, client: modbus.ModbusTcpClient_) -> None: with client: self.serial_number = str(self.client.read_holding_registers(0xFC00, ModbusDataType.UINT_32, unit=self.id)) + def get_imported(self) -> float: + # smarthome legacy + time.sleep(0.1) + return self.client.read_input_registers(0x0048, ModbusDataType.FLOAT_32, unit=self.id) * 1000 + class SdmRegister(IntEnum): VOLTAGE_L1 = 0x00 @@ -42,6 +49,13 @@ def __init__(self, modbus_id: int, client: modbus.ModbusTcpClient_, fault_state: super().__init__(modbus_id, client) self.fault_state = fault_state + def get_power(self) -> Tuple[List[float], float]: + # smarthome legacy + time.sleep(0.1) + powers = self.client.read_input_registers(0x0C, [ModbusDataType.FLOAT_32]*3, unit=self.id) + power = sum(powers) + return powers, power + def get_counter_state(self) -> CounterState: resp = self.client.read_input_registers_bulk( SdmRegister.VOLTAGE_L1, 76, mapping=self.REG_MAPPING, unit=self.id) @@ -78,6 +92,12 @@ def __init__(self, modbus_id: int, client: modbus.ModbusTcpClient_, fault_state: super().__init__(modbus_id, client) self.fault_state = fault_state + def get_power(self) -> Tuple[List[float], float]: + # smarthome legacy + time.sleep(0.1) + power = self.client.read_input_registers(0x0C, ModbusDataType.FLOAT_32, unit=self.id) + return [power, 0, 0], power + def get_counter_state(self) -> CounterState: resp = self.client.read_input_registers_bulk( SdmRegister.VOLTAGE_L1, 76, mapping=self.REG_MAPPING, unit=self.id)