2020-07-19 20:32:17 +00:00
|
|
|
"""Module for light strips (KL430)."""
|
2024-04-16 18:21:20 +00:00
|
|
|
|
2024-04-17 13:39:24 +00:00
|
|
|
from __future__ import annotations
|
2020-07-19 20:32:17 +00:00
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
from ..device_type import DeviceType
|
|
|
|
from ..deviceconfig import DeviceConfig
|
2024-05-10 18:29:28 +00:00
|
|
|
from ..module import Module
|
2024-11-13 17:50:21 +00:00
|
|
|
from ..protocols import BaseProtocol
|
2024-02-04 15:20:08 +00:00
|
|
|
from .iotbulb import IotBulb
|
2024-05-15 17:49:08 +00:00
|
|
|
from .iotdevice import requires_update
|
2024-05-11 18:28:18 +00:00
|
|
|
from .modules.lighteffect import LightEffect
|
2020-07-19 20:32:17 +00:00
|
|
|
|
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
class IotLightStrip(IotBulb):
|
2020-07-19 20:32:17 +00:00
|
|
|
"""Representation of a TP-Link Smart light strip.
|
|
|
|
|
|
|
|
Light strips work similarly to bulbs, but use a different service for controlling,
|
2023-10-29 22:15:42 +00:00
|
|
|
and expose some extra information (such as length and active effect).
|
|
|
|
This class extends :class:`SmartBulb` interface.
|
2020-07-19 20:32:17 +00:00
|
|
|
|
2023-10-29 22:15:42 +00:00
|
|
|
Examples:
|
2020-07-19 20:32:17 +00:00
|
|
|
>>> import asyncio
|
2024-02-04 15:20:08 +00:00
|
|
|
>>> strip = IotLightStrip("127.0.0.1")
|
2020-07-19 20:32:17 +00:00
|
|
|
>>> asyncio.run(strip.update())
|
|
|
|
>>> print(strip.alias)
|
2024-06-03 09:14:10 +00:00
|
|
|
Bedroom Lightstrip
|
2020-07-19 20:32:17 +00:00
|
|
|
|
|
|
|
Getting the length of the strip:
|
|
|
|
|
|
|
|
>>> strip.length
|
|
|
|
16
|
|
|
|
|
|
|
|
Currently active effect:
|
|
|
|
|
|
|
|
>>> strip.effect
|
2024-06-04 17:24:53 +00:00
|
|
|
{'brightness': 100, 'custom': 0, 'enable': 0,
|
|
|
|
'id': 'bCTItKETDFfrKANolgldxfgOakaarARs', 'name': 'Flicker'}
|
2020-07-19 20:32:17 +00:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
The device supports some features that are not currently implemented,
|
|
|
|
feel free to find out how to control them and create a PR!
|
|
|
|
|
|
|
|
|
|
|
|
See :class:`SmartBulb` for more examples.
|
|
|
|
"""
|
|
|
|
|
|
|
|
LIGHT_SERVICE = "smartlife.iot.lightStrip"
|
|
|
|
SET_LIGHT_METHOD = "set_light_state"
|
|
|
|
|
2023-09-13 13:46:38 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
host: str,
|
|
|
|
*,
|
2024-04-17 13:39:24 +00:00
|
|
|
config: DeviceConfig | None = None,
|
|
|
|
protocol: BaseProtocol | None = None,
|
2023-09-13 13:46:38 +00:00
|
|
|
) -> None:
|
2023-12-29 19:17:15 +00:00
|
|
|
super().__init__(host=host, config=config, protocol=protocol)
|
2020-07-19 20:32:17 +00:00
|
|
|
self._device_type = DeviceType.LightStrip
|
2024-05-13 16:34:44 +00:00
|
|
|
|
2024-11-10 18:55:13 +00:00
|
|
|
async def _initialize_modules(self) -> None:
|
2024-05-13 16:34:44 +00:00
|
|
|
"""Initialize modules not added in init."""
|
|
|
|
await super()._initialize_modules()
|
2024-05-10 18:29:28 +00:00
|
|
|
self.add_module(
|
|
|
|
Module.LightEffect,
|
2024-05-11 18:28:18 +00:00
|
|
|
LightEffect(self, "smartlife.iot.lighting_effect"),
|
2024-05-10 18:29:28 +00:00
|
|
|
)
|
2020-07-19 20:32:17 +00:00
|
|
|
|
|
|
|
@property # type: ignore
|
|
|
|
@requires_update
|
|
|
|
def length(self) -> int:
|
|
|
|
"""Return length of the strip."""
|
|
|
|
return self.sys_info["length"]
|