Beispiel #1
0
    def on_input_voltage_down(self, event, *args, **kwargs):
        """React to input voltage drop;
        UPS can transfer to battery if in-voltage is low or
        it can transfer back to input power if volt dropped from
        too high to acceptable;
        """

        asset_event = event.get_next_power_event(self)
        asset_event.out_volt.old = self.state.output_voltage

        battery_level = self.state.battery_level
        should_transfer, reason = self.state.process_voltage(event.in_volt.new)

        upstream_load_change = self._get_ups_load_update(should_transfer)
        if upstream_load_change:
            asset_event.load.old, asset_event.load.new = upstream_load_change

        high_line_t_reason = self.state.InputLineFailCause.highLineVoltage

        # voltage is low, transfer to battery
        if should_transfer and self.state.battery_level:
            self._launch_battery_drain(reason)
            asset_event.out_volt.new = ISystemEnvironment.wallpower_volt_standard(
            )

        # voltage was too high but is okay now
        elif (self.state.transfer_reason == high_line_t_reason
              and reason != high_line_t_reason):
            self._launch_battery_charge(power_up_on_charge=(not battery_level))
        else:
            asset_event.calc_load_from_volt()
            self._update_load(self.state.load + asset_event.load.difference)

        return asset_event
Beispiel #2
0
    def on_input_voltage_up(self, event, *args, **kwargs):
        """React to input voltage spike;
        UPS can transfer to battery if in-voltage is too high;
        It can also transfer back to input power if voltage level is
        within the acceptable threshold;
        """
        asset_event = event.get_next_power_event(self)
        asset_event.out_volt.old = self.state.output_voltage
        asset_event.calc_load_from_volt()

        # process voltage, see if tranfer to battery is needed
        should_transfer, reason = self.state.process_voltage(event.in_volt.new)

        upstream_load_change = self._get_ups_load_update(should_transfer)
        if upstream_load_change:
            asset_event.load.old, asset_event.load.new = upstream_load_change

        # transfer back to input power if ups was running on battery
        if not should_transfer and self.state.on_battery:
            battery_level = self.state.battery_level
            self._launch_battery_charge(power_up_on_charge=(not battery_level))
            if battery_level:
                asset_event.state.new = self.state.power_up()

        # if already on battery (& should stay so), stop voltage propagation
        elif self.state.on_battery:
            asset_event.out_volt.new = asset_event.out_volt.old

        # voltage is too high, transfer to battery
        if should_transfer and reason == self.state.InputLineFailCause.highLineVoltage:
            self._launch_battery_drain(reason)
            asset_event.out_volt.new = ISystemEnvironment.wallpower_volt_standard(
            )

        if not math.isclose(asset_event.load.new, 0) and not math.isclose(
                asset_event.load.new, self.state.load):
            self._update_load(self.state.load + asset_event.load.difference)

        return asset_event