Beispiel #1
0
 def store_error(self, component_info: ComponentInfo) -> None:
     try:
         if self.fault_state is not FaultStateLevel.NO_ERROR:
             log.MainLogger().error(component_info.name + ": FaultState " +
                                    str(self.fault_state) + ", FaultStr " +
                                    self.fault_str + ", Traceback: \n" +
                                    traceback.format_exc())
         ramdisk = compatibility.is_ramdisk_in_use()
         if ramdisk:
             topic = self.type_topic_mapping_comp.get(
                 component_info.type, component_info.type)
             prefix = "openWB/set/" + topic + "/"
             if component_info.id is not None:
                 if topic == "lp":
                     prefix += str(component_info.id) + "/socF"
                 else:
                     prefix += str(component_info.id) + "/f"
             else:
                 prefix += "f"
             pub.pub_single(prefix + "aultStr", self.fault_str)
             pub.pub_single(prefix + "aultState", self.fault_state.value)
         else:
             topic = self.__type_topic_mapping(component_info.type)
             pub.Pub().pub(
                 "openWB/set/" + topic + "/" + str(component_info.id) +
                 "/get/fault_str", self.fault_str)
             pub.Pub().pub(
                 "openWB/set/" + topic + "/" + str(component_info.id) +
                 "/get/fault_state", self.fault_state.value)
     except Exception:
         log.MainLogger().exception("Fehler im Modul fault_state")
Beispiel #2
0
 def update(self) -> None:
     log.MainLogger().debug("Komponente " + self.component_config["name"] +
                            " auslesen.")
     inverter_state = InverterState(
         # for compatibility: in 1.x power URL values are positive!
         power=(-self.__get_power() if compatibility.is_ramdisk_in_use()
                else self.__get_power()),
         counter=self.__get_counter())
     self.__store.set(inverter_state)
Beispiel #3
0
    def __calculate_offset(self, counter: float,
                           daily_yield: float) -> Tuple[float, float, float]:
        ramdisk = compatibility.is_ramdisk_in_use()
        if ramdisk:
            try:
                with open("/var/www/html/openWB/ramdisk/pvkwh_offset",
                          "r") as f:
                    counter_offset = float(f.read())
            except FileNotFoundError as e:
                log.MainLogger().exception(str(e))
                counter_offset = 0
            try:
                with open("/var/www/html/openWB/ramdisk/pvkwh_start",
                          "r") as f:
                    counter_start = float(f.read())
            except FileNotFoundError as e:
                log.MainLogger().exception(str(e))
                counter_start = counter - daily_yield
                with open("/var/www/html/openWB/ramdisk/pvkwh_start",
                          "w") as f:
                    f.write(str(counter_start))
        else:
            topic = "openWB/system/device/" + str(self.__device_id)+"/component/" + \
                str(self.component_config["id"])+"/counter_offset"
            counter_offset = Offset().offset(topic)
            if counter_offset is None:
                counter_offset = 0
            topic = "openWB/system/device/" + str(self.__device_id)+"/component/" + \
                str(self.component_config["id"])+"/counter_start"
            counter_start = Offset().offset(topic)

        if counter_start is not None:
            counter_new = counter_start + daily_yield + counter_offset
            if counter_new > counter:
                if counter_new - counter >= 100:
                    # Korrigiere Abweichung
                    counter_diff = counter_new - counter - 99
                    counter_offset -= counter_diff
                    counter_new -= counter_diff
                counter = counter_new
            else:
                # Berechne Abweichung als Mittelwert von aktueller und bisheriger Abweichung
                counter_offset = round(
                    (counter_offset + counter - counter_start - daily_yield) /
                    2)
        else:
            counter_start = 0
        return counter, counter_start, counter_offset
Beispiel #4
0
 def __add_and_save_offset(self, daily_yield: float, counter: float,
                           counter_start: float,
                           counter_offset: float) -> float:
     ramdisk = compatibility.is_ramdisk_in_use()
     if daily_yield == 0 and \
        counter > counter_start + counter_offset and \
        self.component_config["configuration"]["ip_address2"] == "none":
         if ramdisk:
             with open("/var/www/html/openWB/ramdisk/pvkwh_start",
                       "w") as f:
                 f.write(str(counter))
             with open("/var/www/html/openWB/ramdisk/pvkwh", "r") as ff:
                 counter_old = float(ff.read())
         else:
             topic = "openWB/set/system/device/" + str(self.__device_id)+"/component/" + \
                 str(self.component_config["id"])+"/pvkwh_start"
             pub.pub_single(topic, counter)
             topic = "openWB/pv/" + str(
                 self.component_config["id"]) + "/counter"
             try:
                 counter_old = float(Offset().offset(topic))
             except ValueError:
                 counter_old = 0
         counter_offset = counter_old - counter
         counter += counter_offset
         if ramdisk:
             with open("/var/www/html/openWB/ramdisk/pvkwh_offset",
                       "w") as f:
                 f.write(str(counter_offset))
         else:
             topic = "openWB/set/system/device/" + str(self.__device_id)+"/component/" + \
                 str(self.component_config["id"])+"/counter_offset"
             pub.pub_single(topic, counter_offset)
     else:
         if ramdisk:
             with open("/var/www/html/openWB/ramdisk/pvkwh_offset",
                       "w") as f:
                 f.write(str(counter_offset))
         else:
             topic = "openWB/set/system/device/" + str(self.__device_id)+"/component/" + \
                 str(self.component_config["id"])+"/counter_offset"
             pub.pub_single(topic, counter_offset)
     return counter
Beispiel #5
0
    def update(self) -> None:
        power = (-self.__get_power()
                 if compatibility.is_ramdisk_in_use() else self.__get_power())
        exported = self.__get_exported()
        if exported is None:
            topic_str = "openWB/set/system/device/" + \
                str(self.__device_id)+"/component/" + \
                str(self.component_config.id)+"/"
            _, exported = self.__sim_count.sim_count(
                power,
                topic=topic_str,
                data=self.simulation,
                prefix="pv%s" % ("" if self.component_config.id == 1 else "2"))

        inverter_state = InverterState(
            # for compatibility: in 1.x power URL values are positive!
            power=power,
            exported=exported)
        self.__store.set(inverter_state)
Beispiel #6
0
 def get_sim_counter(self):
     try:
         ramdisk = compatibility.is_ramdisk_in_use()
         return SimCountLegacy if ramdisk else SimCount
     except Exception as e:
         process_error(e)
Beispiel #7
0
def get_counter_value_store(component_num: int) -> ValueStore[CounterState]:
    return LoggingValueStore(
        CounterValueStoreRamdisk() if compatibility.is_ramdisk_in_use(
        ) else CounterValueStoreBroker(component_num))
Beispiel #8
0
def get_counter_value_store(component_num: int) -> ValueStore[CounterState]:
    if compatibility.is_ramdisk_in_use():
        return CounterValueStoreRamdisk()
    return CounterValueStoreBroker(component_num)
Beispiel #9
0
def get_inverter_value_store(component_num: int) -> ValueStore[InverterState]:
    return LoggingValueStore(
        (InverterValueStoreRamdisk if compatibility.is_ramdisk_in_use() else
         InverterValueStoreBroker)(component_num))
Beispiel #10
0
def get_bat_value_store(component_num: int) -> ValueStore[BatState]:
    return LoggingValueStore(
        (BatteryValueStoreRamdisk if compatibility.is_ramdisk_in_use() else
         BatteryValueStoreBroker)(component_num))
Beispiel #11
0
def get_car_value_store(id: int) -> ValueStore[CarState]:
    if compatibility.is_ramdisk_in_use():
        return CarValueStoreRamdisk(id)
    return CarValueStoreBroker(id)