def __init__(self, sid: str, gateway: ZigbeeGateway): super().__init__(sid, gateway) self.status.model = 'plug' self.status.add_alias('status', 'power') self.status.register_attribute(Attribute('inuse', str)) self.status.register_attribute(Attribute('power_consumed', str)) self.status.register_attribute(Attribute('load_power', str)) self.gateway.register_sub_device(self)
def __init__(self, sid:str) -> None: self.status: DeviceStatus = DeviceStatus() for _attr in self._attr_list: self.status.register_attribute(deepcopy(_attr)) self.status.register_attribute(Attribute('sid', str, value=sid, readonly=True)) self.status.register_attribute(Attribute('name', dict)) self.status.register_attribute(Attribute('place', dict)) self.status.register_attribute(Attribute('model', str))
class Hsv(Trait): _commands: Tuple[str, ...] = ('set_hsv', ) _attributes: Tuple[Attribute, Attribute] = (Attribute('hue', int), Attribute('sat', int)) @abstractmethod def set_hsv(self, hue: int, sat: int): pass
def __init__(self, sid: str, gateway: ZigbeeGateway): super().__init__(sid, gateway) self.status.model = 'ctrl_neutral2' self.status.register_attribute(Attribute('left', str)) self.status.register_attribute(Attribute('right', str)) self.status.add_alias('channel_0', 'left') self.status.add_alias('channel_1', 'right') self.status.switches = ['left', 'right'] self.gateway.register_sub_device(self)
def __init__(self, sid:str): super().__init__(sid) self.min_ct:int = 1700 self.max_ct:int = 6500 self.status.register_attribute(Attribute('ip', str)) self.status.register_attribute(Attribute('port', int)) self.status.register_attribute(Attribute('color_mode', int)) self._init_device() self.api = YeelightApi(self.status.ip, self.status.port) self.watcher = Watcher(YeelightWatcher(self)) self.watcher.add_report_handler(self.status.update)
def __init__(self, ip: str, mac: str = '', psk: str = '0000', sid: str = ''): super().__init__(sid) self.status.register_attribute(Attribute('ip', str, value=ip)) self.status.register_attribute(Attribute('psk', str, value=psk)) self.status.register_attribute(Attribute('mac', str, value=mac)) self.status.add_alias('dispNum', 'channel') self._event: Event = None self.dev_api = BraviaApi(ip, mac, psk) self._dev_init() self.watcher = Watcher(BraviaWatcher(30, self))
class Scene(Trait): _commands: Tuple[str, ...] = ('set_scene', ) _attributes: Tuple[Attribute] = (Attribute('scene', str), ) @abstractmethod def set_scene(self, scene: Any, args: List[Any] = []): pass
class Dimmer(Trait): _commands: Tuple[str, ...] = ('set_bright', ) _attributes: Tuple[Attribute, ...] = (Attribute('bright', int), ) @abstractmethod def set_bright(self, value: int): pass
class MultiSwitch(Trait): _commands: Tuple[str, ...] = ('on', 'off') _attributes: Tuple[Attribute, ...] = (Attribute('switches', list, readonly=True, oneshot=True), ) @abstractmethod def on(self, switch_name: str): pass @abstractmethod def off(self, switch_name: str): pass @abstractmethod def toggle(self, switch_name: str): pass @abstractmethod def is_on(self, switch_name: str) -> bool: pass @abstractmethod def is_off(self, switch_name: str) -> bool: pass
class ColorTemperature(Trait): _commands: Tuple[str, ...] = ('set_ct_pc', ) _attributes: Tuple[Attribute] = (Attribute('ct_pc', int), ) @abstractmethod def set_ct_pc(self, pc: int): pass
def test_a_readonly_oneshot(self): ro_attr = Attribute('test_oneshot', str, readonly=True, oneshot=True) self.status.register_attribute(ro_attr) self.status.test_oneshot = 'foo' self.assertEqual(self.status.test_oneshot, 'foo') with self.assertRaises(AttributeError): self.status.test_oneshot = 'bar'
class OpenClose(Trait): _commands: Set[str] = set() _attributes: Tuple[Attribute, ...] = (Attribute('status', str), ) @abstractmethod def is_open(self) -> bool: pass @abstractmethod def is_close(self) -> bool: pass
class Rgb(Trait): _commands: Tuple[str, ...] = ('set_rgb', 'set_color') _attributes: Tuple[Attribute] = (Attribute('rgb', int), ) @abstractmethod def set_rgb(self, red: int, green: int, blue: int): pass @abstractmethod def set_color(self, rgb: int): pass
class SuspendResume(Trait): _commands: Tuple[str, ...] = ('suspend', 'resume') _attributes: Tuple[Attribute, ...] = (Attribute('power_state', str), ) @abstractmethod def suspend(self) -> None: pass @abstractmethod def resume(self) -> None: pass
class Contact(Trait): _commands: Set[str] = set() _attributes: Tuple[Attribute, ...] = (Attribute('contact', bool), ) @abstractmethod def is_open(self) -> bool: pass @abstractmethod def is_close(self) -> bool: pass
class Channels(Trait): _commands: Tuple[str, ...] = ('channel_up', 'channel_down', 'set_channel') _attributes: Tuple[Attribute] = (Attribute('channel', str), ) @abstractmethod def channel_up(self): pass @abstractmethod def channel_down(self): pass @abstractmethod def set_channel(self, value: int): pass
class Volume(Trait): _commands: Tuple[str, ...] = ('volume_up', 'volume_down', 'set_volume') _attributes: Tuple[Attribute] = (Attribute('volume', str), ) @abstractmethod def volume_up(self): pass @abstractmethod def volume_down(self): pass @abstractmethod def set_volume(self, value: int): pass @abstractmethod def set_mute(self, status: bool): pass
class OnOff(Trait): _commands: Tuple[str, ...] = ('on', 'off') _attributes: Tuple[Attribute, ...] = (Attribute('power', str), ) @abstractmethod def on(self) -> None: """ Device power on """ pass @abstractmethod def off(self) -> None: pass @abstractmethod def is_on(self) -> bool: pass @abstractmethod def is_off(self) -> bool: pass
def test_a_sid(self): sid_attr = Attribute('sid', str, value="123345678900") self.status.register_attribute(sid_attr) self.assertEqual(self.status.sid, "123345678900")
def __init__(self, sid: str, gateway: ZigbeeGateway) -> None: super().__init__(sid, gateway) self.status.model = 'GZCGQ01LM' self.status.register_attribute(Attribute('lux', int)) self.gateway.register_sub_device(self)
def test_a_readonly(self): ro_attr = Attribute('test', str, readonly=True) self.status.register_attribute(ro_attr) with self.assertRaises(AttributeError): self.status.test = 'foo'
def __init__(self, sid: str, gateway: AqaraGateway): super().__init__(sid, gateway) self.status.register_attribute(Attribute('proto_version', str)) self.status.bright = 255 self.gateway.register_sub_device(self)
class MotionStatus(Trait): _commands: Tuple[str, ...] = tuple() _attributes: Tuple[Attribute, ...] = (Attribute('occupancy', bool), )
class TemperatureStatus(Trait): _commands: Tuple[str, ...] = tuple() _attributes: Tuple[Attribute] = (Attribute('temperature', str), )
class HumidityStatus(Trait): _commands: Tuple[str, ...] = tuple() _attributes: Tuple[Attribute] = (Attribute('humidity', str), )
class PressureStatus(Trait): _commands: Tuple[str, ...] = tuple() _attributes: Tuple[Attribute] = (Attribute('pressure', str), )
def __init__(self, sid:str): super().__init__(sid) self.status.register_attribute(Attribute('ct', int)) self.min_ct = 2700 self.max_ct = 6500
class IlluminanceStatus(Trait): _commands: Tuple[str, ...] = tuple() _attributes: Tuple[Attribute] = (Attribute('illuminance', int), )