pywemo.ouimeaux_device.dimmer
Representation of a WeMo Dimmer device.
1"""Representation of a WeMo Dimmer device.""" 2from __future__ import annotations 3 4from .api.long_press import LongPressMixin 5from .api.service import RequiredService 6from .switch import Switch 7 8 9class Dimmer(Switch): 10 """Representation of a WeMo Dimmer device.""" 11 12 _brightness: int | None = None 13 14 @property 15 def _required_services(self) -> list[RequiredService]: 16 return super()._required_services + [ 17 RequiredService(name="basicevent", actions=["SetBinaryState"]), 18 ] 19 20 def get_brightness(self, force_update: bool = False) -> int: 21 """Get brightness from device.""" 22 self.get_state(force_update) 23 assert self._brightness is not None 24 return self._brightness 25 26 def set_brightness(self, brightness: int) -> None: 27 """Set the brightness of this device to an integer between 1-100.""" 28 # WeMo only supports values between 1-100. WeMo will ignore a 0 29 # brightness value. If 0 is requested, then turn the light off instead. 30 if brightness: 31 self.basicevent.SetBinaryState( 32 BinaryState=1, brightness=brightness 33 ) 34 self._state = 1 35 self._brightness = brightness 36 else: 37 self.off() 38 39 def get_state(self, force_update: bool = False) -> int: 40 """Update the state & brightness for the Dimmer.""" 41 force_update = force_update or ( 42 self._brightness is None 43 and "brightness" not in self.basic_state_params 44 ) 45 state = super().get_state(force_update) 46 if force_update or self._brightness is None: 47 try: 48 brightness = int(self.basic_state_params.get("brightness", 0)) 49 except ValueError: 50 brightness = 0 51 self._brightness = brightness 52 return state 53 54 def subscription_update(self, _type: str, _param: str) -> bool: 55 """Update the dimmer attributes due to a subscription update event.""" 56 if _type == "Brightness": 57 try: 58 self._brightness = int(_param) 59 except ValueError: 60 return False 61 return True 62 return super().subscription_update(_type, _param) 63 64 65class DimmerLongPress(Dimmer, LongPressMixin): 66 """WeMo Dimmer device that supports long press.""" 67 68 69class DimmerV2(Dimmer): 70 """WeMo Dimmer version 2."""
10class Dimmer(Switch): 11 """Representation of a WeMo Dimmer device.""" 12 13 _brightness: int | None = None 14 15 @property 16 def _required_services(self) -> list[RequiredService]: 17 return super()._required_services + [ 18 RequiredService(name="basicevent", actions=["SetBinaryState"]), 19 ] 20 21 def get_brightness(self, force_update: bool = False) -> int: 22 """Get brightness from device.""" 23 self.get_state(force_update) 24 assert self._brightness is not None 25 return self._brightness 26 27 def set_brightness(self, brightness: int) -> None: 28 """Set the brightness of this device to an integer between 1-100.""" 29 # WeMo only supports values between 1-100. WeMo will ignore a 0 30 # brightness value. If 0 is requested, then turn the light off instead. 31 if brightness: 32 self.basicevent.SetBinaryState( 33 BinaryState=1, brightness=brightness 34 ) 35 self._state = 1 36 self._brightness = brightness 37 else: 38 self.off() 39 40 def get_state(self, force_update: bool = False) -> int: 41 """Update the state & brightness for the Dimmer.""" 42 force_update = force_update or ( 43 self._brightness is None 44 and "brightness" not in self.basic_state_params 45 ) 46 state = super().get_state(force_update) 47 if force_update or self._brightness is None: 48 try: 49 brightness = int(self.basic_state_params.get("brightness", 0)) 50 except ValueError: 51 brightness = 0 52 self._brightness = brightness 53 return state 54 55 def subscription_update(self, _type: str, _param: str) -> bool: 56 """Update the dimmer attributes due to a subscription update event.""" 57 if _type == "Brightness": 58 try: 59 self._brightness = int(_param) 60 except ValueError: 61 return False 62 return True 63 return super().subscription_update(_type, _param)
Representation of a WeMo Dimmer device.
def
get_brightness(self, force_update: bool = False) -> int:
21 def get_brightness(self, force_update: bool = False) -> int: 22 """Get brightness from device.""" 23 self.get_state(force_update) 24 assert self._brightness is not None 25 return self._brightness
Get brightness from device.
def
set_brightness(self, brightness: int) -> None:
27 def set_brightness(self, brightness: int) -> None: 28 """Set the brightness of this device to an integer between 1-100.""" 29 # WeMo only supports values between 1-100. WeMo will ignore a 0 30 # brightness value. If 0 is requested, then turn the light off instead. 31 if brightness: 32 self.basicevent.SetBinaryState( 33 BinaryState=1, brightness=brightness 34 ) 35 self._state = 1 36 self._brightness = brightness 37 else: 38 self.off()
Set the brightness of this device to an integer between 1-100.
def
get_state(self, force_update: bool = False) -> int:
40 def get_state(self, force_update: bool = False) -> int: 41 """Update the state & brightness for the Dimmer.""" 42 force_update = force_update or ( 43 self._brightness is None 44 and "brightness" not in self.basic_state_params 45 ) 46 state = super().get_state(force_update) 47 if force_update or self._brightness is None: 48 try: 49 brightness = int(self.basic_state_params.get("brightness", 0)) 50 except ValueError: 51 brightness = 0 52 self._brightness = brightness 53 return state
Update the state & brightness for the Dimmer.
def
subscription_update(self, _type: str, _param: str) -> bool:
55 def subscription_update(self, _type: str, _param: str) -> bool: 56 """Update the dimmer attributes due to a subscription update event.""" 57 if _type == "Brightness": 58 try: 59 self._brightness = int(_param) 60 except ValueError: 61 return False 62 return True 63 return super().subscription_update(_type, _param)
Update the dimmer attributes due to a subscription update event.
Inherited Members
66class DimmerLongPress(Dimmer, LongPressMixin): 67 """WeMo Dimmer device that supports long press."""
WeMo Dimmer device that supports long press.
Inherited Members
WeMo Dimmer version 2.