Exemple #1
0
    def handle_oid_update(self, asset_key, oid, value):
        """React to OID update
        Args:
            asset_key(int): key of the asset oid belongs to
            oid(str): updated oid
            value(str): OID value
        """
        if asset_key not in self._assets:
            logger.warning("Asset [%s] does not exist!", asset_key)
            return

        # get asset key associated with the oid & oid details
        affected_asset_key, oid_details = self._data_source.get_asset_oid_info(
            asset_key, oid
        )

        if not oid_details:
            logger.warning(
                "OID:[%s] for asset:[%s] cannot be processed by engine!", oid, asset_key
            )
            return

        snmp_event = events.SNMPEvent(
            asset=self._assets[affected_asset_key],
            oid=oid,
            oid_value_name=oid_details["specs"][value],
            oid_name=oid_details["name"],
        )

        self._power_iter_handler.queue_iteration(PowerIteration(snmp_event))
Exemple #2
0
    def handle_voltage_update(self, old_voltage, new_voltage):
        """Wallpower voltage changes to a new value,
        initiate a chain of power reactions
        Args:
            old_voltage(float): old voltage value
            new_voltage(float): new wallpower voltage value
        """

        if math.isclose(old_voltage, new_voltage):
            return

        volt_event = events.AssetPowerEvent(
            asset=None, old_out_volt=old_voltage, new_out_volt=new_voltage
        )
        self._notify_trackers(volt_event)
        if math.isclose(old_voltage, 0.0) or math.isclose(new_voltage, 0.0):
            self._notify_trackers(
                events.MainsPowerEvent(mains=int(math.isclose(old_voltage, 0.0)))
            )

        self._power_iter_handler.queue_iteration(PowerIteration(volt_event))
Exemple #3
0
    def handle_state_update(self, asset_key, old_state, new_state):
        """Asset state changes to a new value,
        initiate a chain of power reactions
        Args:
            asset_key(int): key of the updated asset
            state(int): 0 for offline, 1 for online
        """

        if old_state == new_state:
            return

        updated_asset = self._assets[asset_key]

        # notify updated hardware device of button event
        btn_event = (events.PowerButtonOnEvent
                     if new_state else events.PowerButtonOffEvent)

        self._power_iter_handler.queue_iteration(
            PowerIteration(
                btn_event(old_state=old_state,
                          new_state=new_state,
                          asset=updated_asset)))