J. Nick Koston 1 year ago
parent
commit
b10be4e581
5 changed files with 37 additions and 37 deletions
  1. 1 1
      switchbot/__init__.py
  2. 2 1
      switchbot/devices/bot.py
  3. 27 27
      switchbot/devices/bulb.py
  4. 5 7
      switchbot/devices/device.py
  5. 2 1
      switchbot/discovery.py

+ 1 - 1
switchbot/__init__.py

@@ -4,10 +4,10 @@ from __future__ import annotations
 from .adv_parser import SwitchbotSupportedType, parse_advertisement_data
 from .const import SwitchbotModel
 from .devices.bot import Switchbot
+from .devices.bulb import ColorMode, SwitchbotBulb
 from .devices.curtain import SwitchbotCurtain
 from .devices.device import SwitchbotDevice
 from .devices.plug import SwitchbotPlugMini
-from .devices.bulb import SwitchbotBulb, ColorMode
 from .discovery import GetSwitchbotDevices
 from .models import SwitchBotAdvertisement
 

+ 2 - 1
switchbot/devices/bot.py

@@ -4,7 +4,8 @@ from __future__ import annotations
 import logging
 from typing import Any
 
-from .device import DEVICE_SET_EXTENDED_KEY, DEVICE_SET_MODE_KEY, SwitchbotDevice
+from .device import (DEVICE_SET_EXTENDED_KEY, DEVICE_SET_MODE_KEY,
+                     SwitchbotDevice)
 
 # Bot keys
 PRESS_KEY = "570100"

+ 27 - 27
switchbot/devices/bulb.py

@@ -39,6 +39,33 @@ class SwitchbotBulb(SwitchbotDevice):
         super().__init__(*args, **kwargs)
         self._state: dict[str, Any] = {}
 
+    @property
+    def on(self) -> bool:
+        """Return if bulb is on."""
+        return self.is_on()
+
+    @property
+    def rgb(self) -> tuple[int, int, int] | None:
+        """Return the current rgb value."""
+        if "r" not in self._state or "g" not in self._state or "b" not in self._state:
+            return None
+        return self._state["r"], self._state["g"], self._state["b"]
+
+    @property
+    def color_temp(self) -> int | None:
+        """Return the current color temp value."""
+        return self._state.get("cw")
+
+    @property
+    def brightness(self) -> int | None:
+        """Return the current brightness value."""
+        return self._get_adv_value("brightness")
+
+    @property
+    def color_mode(self) -> ColorMode:
+        """Return the current color mode."""
+        return ColorMode(self._get_adv_value("color_mode") or 0)
+
     async def update(self, interface: int | None = None) -> None:
         """Update state of device."""
         result = await self._sendcommand(BULB_REQUEST)
@@ -95,33 +122,6 @@ class SwitchbotBulb(SwitchbotDevice):
         """Return bulb state from cache."""
         return self._get_adv_value("isOn")
 
-    @property
-    def on(self) -> bool:
-        """Return if bulb is on."""
-        return self.is_on()
-
-    @property
-    def rgb(self) -> tuple[int, int, int] | None:
-        """Return the current rgb value."""
-        if "r" not in self._state or "g" not in self._state or "b" not in self._state:
-            return None
-        return self._state["r"], self._state["g"], self._state["b"]
-
-    @property
-    def color_temp(self) -> int | None:
-        """Return the current color temp value."""
-        return self._state.get("cw")
-
-    @property
-    def brightness(self) -> int | None:
-        """Return the current brightness value."""
-        return self._get_adv_value("brightness")
-
-    @property
-    def color_mode(self) -> ColorMode:
-        """Return the current color mode."""
-        return ColorMode(self._get_adv_value("color_mode") or 0)
-
     def _update_state(self, result: bytes) -> None:
         """Update device state."""
         self._state["r"] = result[3]

+ 5 - 7
switchbot/devices/device.py

@@ -10,14 +10,12 @@ from uuid import UUID
 import async_timeout
 from bleak import BleakError
 from bleak.backends.device import BLEDevice
-from bleak.backends.service import BleakGATTCharacteristic, BleakGATTServiceCollection
+from bleak.backends.service import (BleakGATTCharacteristic,
+                                    BleakGATTServiceCollection)
 from bleak.exc import BleakDBusError
-from bleak_retry_connector import (
-    BleakClientWithServiceCache,
-    BleakNotFoundError,
-    ble_device_has_changed,
-    establish_connection,
-)
+from bleak_retry_connector import (BleakClientWithServiceCache,
+                                   BleakNotFoundError, ble_device_has_changed,
+                                   establish_connection)
 
 from ..const import DEFAULT_RETRY_COUNT, DEFAULT_SCAN_TIMEOUT
 from ..discovery import GetSwitchbotDevices

+ 2 - 1
switchbot/discovery.py

@@ -10,7 +10,8 @@ from bleak.backends.device import BLEDevice
 from bleak.backends.scanner import AdvertisementData
 
 from .adv_parser import parse_advertisement_data
-from .const import DEFAULT_RETRY_COUNT, DEFAULT_RETRY_TIMEOUT, DEFAULT_SCAN_TIMEOUT
+from .const import (DEFAULT_RETRY_COUNT, DEFAULT_RETRY_TIMEOUT,
+                    DEFAULT_SCAN_TIMEOUT)
 from .models import SwitchBotAdvertisement
 
 _LOGGER = logging.getLogger(__name__)