pywemo.ouimeaux_device.dimmer

Representation of a WeMo Dimmer device.

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

Representation of a WeMo Dimmer device.

def get_brightness(self, force_update: 'bool' = False) -> 'int':
22    def get_brightness(self, force_update: bool = False) -> int:
23        """Get brightness from device."""
24        self.get_state(force_update)
25        assert self._brightness is not None
26        return self._brightness

Get brightness from device.

def set_brightness(self, brightness: 'int') -> 'None':
28    def set_brightness(self, brightness: int) -> None:
29        """Set the brightness of this device to an integer between 1-100."""
30        # WeMo only supports values between 1-100. WeMo will ignore a 0
31        # brightness value. If 0 is requested, then turn the light off instead.
32        if brightness:
33            self.basicevent.SetBinaryState(
34                BinaryState=1, brightness=brightness
35            )
36            self._state = 1
37            self._brightness = brightness
38        else:
39            self.off()

Set the brightness of this device to an integer between 1-100.

def get_state(self, force_update: 'bool' = False) -> 'int':
41    def get_state(self, force_update: bool = False) -> int:
42        """Update the state & brightness for the Dimmer."""
43        force_update = force_update or (
44            self._brightness is None
45            and "brightness" not in self.basic_state_params
46        )
47        state = super().get_state(force_update)
48        if force_update or self._brightness is None:
49            try:
50                brightness = int(self.basic_state_params.get("brightness", 0))
51            except ValueError:
52                brightness = 0
53            self._brightness = brightness
54        return state

Update the state & brightness for the Dimmer.

def subscription_update(self, _type: 'str', _param: 'str') -> 'bool':
56    def subscription_update(self, _type: str, _param: str) -> bool:
57        """Update the dimmer attributes due to a subscription update event."""
58        if _type == "Brightness":
59            try:
60                self._brightness = int(_param)
61            except ValueError:
62                return False
63            return True
64        return super().subscription_update(_type, _param)

Update the dimmer attributes due to a subscription update event.

class DimmerLongPress(Dimmer, pywemo.ouimeaux_device.api.long_press.LongPressMixin):
67class DimmerLongPress(Dimmer, LongPressMixin):
68    """WeMo Dimmer device that supports long press."""

WeMo Dimmer device that supports long press.

class DimmerV2(Dimmer):
71class DimmerV2(Dimmer):
72    """WeMo Dimmer version 2."""

WeMo Dimmer version 2.