Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
add dim to night_light (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlebourl authored Sep 19, 2022
1 parent 83439e7 commit f15e78e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions custom_components/vesync/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ def __init__(self, device):
"""Initialize the VeSync device."""
super().__init__(device)
self.device = device
self.has_brightness = has_feature(
self.device, "details", "night_light_brightness"
)

@property
def unique_id(self):
Expand All @@ -220,16 +223,16 @@ def brightness(self):
"""Get night light brightness."""
return (
_vesync_brightness_to_ha(self.device.details["night_light_brightness"])
if has_feature(self.device, "details", "night_light_brightness")
else None
if self.has_brightness
else {"on": 255, "dim": 125, "off": 0}[self.device.details["night_light"]]
)

@property
def is_on(self):
"""Return True if night light is on."""
if has_feature(self.device, "details", "night_light"):
return self.device.details["night_light"] == "on"
if has_feature(self.device, "details", "night_light_brightness"):
return self.device.details["night_light"] in ["on", "dim"]
if self.has_brightness:
return self.device.details["night_light_brightness"] > 0

@property
Expand All @@ -240,10 +243,14 @@ def entity_category(self):
def turn_on(self, **kwargs):
"""Turn the night light on."""
if self.device.config_dict["module"] == "VeSyncAirBypass":
self.device.set_night_light("on")
if ATTR_BRIGHTNESS in kwargs and kwargs[ATTR_BRIGHTNESS] < 255:
self.device.set_night_light("dim")
else:
self.device.set_night_light("on")
elif ATTR_BRIGHTNESS in kwargs:
brightness = _ha_brightness_to_vesync(kwargs[ATTR_BRIGHTNESS])
self.device.set_night_light_brightness(brightness)
self.device.set_night_light_brightness(
_ha_brightness_to_vesync(kwargs[ATTR_BRIGHTNESS])
)
else:
self.device.set_night_light_brightness(100)

Expand Down

0 comments on commit f15e78e

Please sign in to comment.