def _update_battery_process_speed(self, process_channel, factor): """Speed up/slow down battery related process""" IStateManager.get_store().publish( process_channel, json.dumps({ "key": self.key, "factor": factor }))
def update_thermal_storage_target(cls, attr): """Add new storage entity affected by a sensor Notify sensors if the relationship is new""" new_rel = sys_modeler.set_thermal_storage_target(attr) if not new_rel: return target_data = { "key": attr["asset_key"], "relationship": { "source": attr["source_sensor"], "event": attr["event"], "controller": attr["controller"], }, } if "drive" in attr and attr["drive"]: channel = RedisChannels.str_drive_conf_th_channel target_data["relationship"]["drive"] = attr["drive"] else: channel = RedisChannels.str_cv_conf_th_channel target_data["relationship"]["cv"] = attr["cache_vault"] IStateManager.get_store().publish(channel, json.dumps(target_data))
def _update_battery(self, charge_level): """Battery level setter Args: charge_level(int): new charge level in high-precision format (0-1000) """ # make sure new charge level is within acceptable range charge_level = max(charge_level, 0) charge_level = min(charge_level, self._max_battery_level) IStateManager.get_store().set(self.redis_key + ":battery", int(charge_level))
def update_thermal_cpu_target(cls, attr): """Create new or update existing thermal relationship between CPU usage and sensor""" new_rel = sys_modeler.set_thermal_cpu_target(attr) if not new_rel: return IStateManager.get_store().publish( RedisChannels.cpu_usg_conf_th_channel, json.dumps( { "key": attr["asset_key"], "relationship": {"target": attr["target_sensor"]}, } ), )
def update_thermal_sensor_target(cls, attr): """Create new or update existing thermal relationship between 2 sensors""" new_rel = sys_modeler.set_thermal_sensor_target(attr) if not new_rel: return IStateManager.get_store().publish( RedisChannels.sensor_conf_th_channel, json.dumps({ "key": attr["asset_key"], "relationship": { "source": attr["source_sensor"], "target": attr["target_sensor"], "event": attr["event"], }, }), )
def get_oid_value(self, object_id, key=None): """Retrieve value for a specific OID """ if key is None: key = self.key redis_store = IStateManager.get_store() rkey = format_as_redis_key(str(key), object_id.oid, key_formatted=False) return redis_store.get(rkey).decode().split("|")[1]
def _update_oid_value(self, object_id, oid_value): """Update oid with a new value Args: object_id(ISnmpDeviceStateManager.ObjectIdentity): SNMP object id oid_value(object): OID value in rfc1902 format """ redis_store = IStateManager.get_store() rkey = format_as_redis_key(str(self._asset_key), object_id.oid, key_formatted=False) data_type = int(redis_store.get(rkey).decode().split("|")[0]) rvalue = "{}|{}".format(data_type, oid_value) redis_store.set(rkey, rvalue)
def battery_level(self): """Get current level (high-precision)""" battery_lvl = IStateManager.get_store().get(self.redis_key + ":battery") return int(battery_lvl.decode()) if battery_lvl else 0
def cpu_load(self) -> int: """Get latest recorded CPU load in percentage (between 0 and 100)""" cpu_load = IStateManager.get_store().get(self.redis_key + ":cpu_load") return int(cpu_load.decode()) if cpu_load else 0