Skip to content

Commit 13bc254

Browse files
committed
Add basic support for front LED
1 parent d3cb559 commit 13bc254

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

dingz/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
FIRMWARE = "/load"
2626

2727
SETTINGS = "settings"
28-
FRONT_LED = "led/get"
28+
FRONT_LED_GET = "led/get"
29+
FRONT_LED_SET = "led/set"
2930
BUTTON_ACTIONS = "action"
3031

3132
# Configuration endpoints

dingz/dingz.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from yarl import URL
66

77
from . import _request as request
8-
from .constants import API, DEVICE_INFO, TEMPERATURE, LIGHT
8+
from .constants import API, DEVICE_INFO, TEMPERATURE, LIGHT, FRONT_LED_GET, FRONT_LED_SET
9+
from .exceptions import DingzError
910

1011
_LOGGER = logging.getLogger(__name__)
1112

@@ -43,6 +44,23 @@ async def get_light(self) -> None:
4344
self._intensity = response["intensity"]
4445
self._day = response["day"]
4546

47+
async def enabled(self) -> bool:
48+
"""Return true if front LED is on."""
49+
url = URL(self.uri).join(URL(FRONT_LED_GET))
50+
response = await request(self, uri=url)
51+
return bool(response["on"])
52+
53+
async def turn_on(self) -> None:
54+
"""Enable/turn on the front LED."""
55+
data = {"action": "on"}
56+
url = URL(self.uri).join(URL(FRONT_LED_SET))
57+
await request(self, uri=url, method="POST", data=data)
58+
59+
async def turn_off(self) -> None:
60+
"""Disable/turn off the front LED."""
61+
url = URL(self.uri).join(URL(FRONT_LED_SET))
62+
await request(self, uri=url, method="POST", data={"action": "off"})
63+
4664
@property
4765
def device_details(self) -> str:
4866
"""Return the current device details."""

example.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ async def main():
1818
await dingz.get_temperature()
1919
print("Temperature:", dingz.temperature)
2020

21+
# Turn on the front LED
22+
print("Turning Front LED on...")
23+
await dingz.turn_on()
24+
await asyncio.sleep(3)
25+
print("Front LED:", await dingz.enabled())
26+
await dingz.turn_off()
27+
print("Front LED:", await dingz.enabled())
28+
2129

2230
if __name__ == "__main__":
2331
loop = asyncio.get_event_loop()

0 commit comments

Comments
 (0)