#!/usr/bin/env python # -*- coding: utf-8 -*- # from devices.base import base import logging class silvercrest_powerplug(base): """ Communication (MQTT) silvercrest_powerplug { | "state": ["ON" / "OFF"] | "linkquality": [0...255] lqi | } +- get { | "state": "" | } +- set { "state": ["ON" / "OFF"] } """ KEY_LINKQUALITY = "linkquality" KEY_OUTPUT_0 = "state" # TX_TYPE = base.TX_DICT TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0] # RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0] RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0] def __state_logging__(self, inst, key, data): if key in [self.KEY_OUTPUT_0]: self.logger.info("State change of '%s' to '%s'", key, repr(data)) # # RX # @property def output_0(self): """rv: [True, False]""" return self.get(self.KEY_OUTPUT_0) @property def linkquality(self): """rv: numeric value""" return self.get(self.KEY_LINKQUALITY) # # TX # def set_output_0(self, state): """state: [True, False]""" self.send_command(self.KEY_OUTPUT_0, state) def set_output_0_mcb(self, device, key, data): self.set_output_0(data) def toggle_output_0_mcb(self, device, key, data): self.set_output_0(not self.output_0) def all_off(self): if self.output_0: self.set_output_0(False) class silvercrest_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" # TX_TYPE = base.TX_DICT # RX_KEYS = [KEY_BATTERY, KEY_BATTERY_LOW, KEY_LINKQUALITY, KEY_OCCUPANCY, KEY_UNMOUNTED, KEY_VOLTAGE] def __init__(self, mqtt_client, topic): super().__init__(mqtt_client, topic) def __state_logging__(self, inst, key, data): if key in [self.KEY_OCCUPANCY, self.KEY_UNMOUNTED]: self.logger.info("State change of '%s' to '%s'", key, repr(data)) # # RX # @property def linkquality(self): """rv: numeric value""" return self.get(self.KEY_LINKQUALITY) @property def battery(self): """rv: numeric value""" return self.get(self.KEY_BATTERY)