Ejemplo n.º 1
0
    def update(self) -> None:
        log.debug("Beginning update")
        with MultiComponentUpdateContext(self._components):
            if not self._components:
                raise FaultState.warning("Keine Komponenten konfiguriert")

            with SpeedwireListener(timeout_seconds) as speedwire:
                self.__read_speedwire(speedwire)

        log.debug("Update complete")
Ejemplo n.º 2
0
    def update(self, response) -> None:
        power = float(response["statistics"]["batconv_power"])
        if response["direction"]["is_battery_discharging_"] == "1":
            power = power * -1
        try:
            soc = float(response["statistics"]["bat_user_soc"])
        except ValueError:
            FaultState.warning(
                'Speicher-SOC ist nicht numerisch und wird auf 0 gesetzt.').store_error(self.component_info)
            soc = 0

        topic_str = "openWB/set/system/device/" + str(
            self.__device_id)+"/component/"+str(self.component_config.id)+"/"
        imported, exported = self.__sim_count.sim_count(
            power, topic=topic_str, data=self.__simulation, prefix="speicher"
        )
        bat_state = BatState(
            power=power,
            soc=soc,
            imported=imported,
            exported=exported
        )
        self.__store.set(bat_state)
Ejemplo n.º 3
0
    def __read_registers(self,
                         read_register_method: Callable,
                         address: int,
                         types: Union[Iterable[ModbusDataType],
                                      ModbusDataType],
                         byteorder: Endian = Endian.Big,
                         wordorder: Endian = Endian.Big,
                         **kwargs):
        try:
            multi_request = isinstance(types, Iterable)
            if not multi_request:
                types = [types]

            def divide_rounding_up(numerator: int, denominator: int):
                return -(-numerator // denominator)

            number_of_addresses = sum(
                divide_rounding_up(t.bits, _MODBUS_HOLDING_REGISTER_SIZE)
                for t in types)
            response = read_register_method(address, number_of_addresses,
                                            **kwargs)
            if response.isError():
                raise FaultState.error(__name__ + " " + str(response))
            decoder = BinaryPayloadDecoder.fromRegisters(
                response.registers, byteorder, wordorder)
            result = [
                struct.unpack(">e",
                              struct.pack(">H", decoder.decode_16bit_uint()))
                if t == ModbusDataType.FLOAT_16 else getattr(
                    decoder, t.decoding_method)() for t in types
            ]
            return result if multi_request else result[0]
        except pymodbus.exceptions.ConnectionException as e:
            raise FaultState.error(
                "TCP-Client konnte keine Verbindung zu " + str(self.address) +
                ":" + str(self.port) +
                " aufbauen. Bitte Einstellungen (IP-Adresse, ..) und " +
                "Hardware-Anschluss prüfen.") from e
        except pymodbus.exceptions.ModbusIOException as e:
            raise FaultState.warning(
                "TCP-Client " + str(self.address) + ":" + str(self.port) +
                " konnte keinen Wert abfragen. Falls vorhanden, parallele Verbindungen, zB. node red,"
                +
                "beenden und bei anhaltender Fehlermeldung Zähler neustarten."
            ) from e
        except Exception as e:
            raise FaultState.error(__name__ + " " + str(type(e)) + " " +
                                   str(e)) from e