from devices.base import base from devices.tradfri import sw as tradfri_sw from devices.tradfri import sw_br_ct as tradfri_sw_br_ct import json class sw(tradfri_sw): pass class sw_br_ct(tradfri_sw_br_ct): def set_state(self, value): self.__set__("state", "on" if value else "off") def power_on_action(self): self["state"] = "on" class motion_sensor(base): """ Communication (MQTT) silvercrest_motion_sensor { battery: [0...100] % battery_low: [True, False] linkquality: [0...255] lqi occupancy: [True, False] tamper: [True, False] voltage: [0...] mV } """ KEY_BATTERY = "battery" KEY_BATTERY_LOW = "battery_low" KEY_LINKQUALITY = "linkquality" KEY_OCCUPANCY = "occupancy" KEY_UNMOUNTED = "tamper" KEY_VOLTAGE = "voltage" # PROPERTIES = [KEY_OCCUPANCY, KEY_UNMOUNTED] def __init__(self, mqtt_client, topic, **kwargs): super().__init__(mqtt_client, topic, **kwargs) # self[self.KEY_OCCUPANCY] = False # cmd_base = self.topic.replace('/', '.') + '.' self.user_cmds = { cmd_base + 'toggle_occupancy': self.__ui_toggle_occupancy__, } def send_device_status(self): self.logger.info("Sending status: %s", repr(self)) self.mqtt_client.send(self.topic, json.dumps(self)) def __ui_toggle_occupancy__(self, *args): self.__set__(self.KEY_OCCUPANCY, not self.get(self.KEY_OCCUPANCY)) self.send_device_status()