mirror of
https://github.com/micahqcade/custom_vesync.git
synced 2025-03-12 07:40:07 +01:00
Fix/regression from 0.1.11 on lights. (#42)
* ignore trunk log * fix night light brightness for unsupported devices * rename night light class
This commit is contained in:
parent
f7d1947423
commit
dc222cb03c
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
.vscode/**
|
||||
**/__pycache__/**
|
||||
Config/**
|
||||
.trunk/logs
|
||||
|
@ -14,7 +14,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .common import VeSyncDevice
|
||||
from .common import VeSyncDevice, has_feature
|
||||
from .const import DEV_TYPE_TO_HA, DOMAIN, VS_DISCOVERY, VS_LIGHTS
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -51,7 +51,7 @@ def _setup_entities(devices, async_add_entities):
|
||||
if DEV_TYPE_TO_HA.get(dev.device_type) in ("bulb-tunable-white",):
|
||||
entities.append(VeSyncTunableWhiteLightHA(dev))
|
||||
if dev.night_light:
|
||||
entities.append(VeSyncHumidifierNightLightHA(dev))
|
||||
entities.append(VeSyncNightLightHA(dev))
|
||||
|
||||
async_add_entities(entities, update_before_add=True)
|
||||
|
||||
@ -66,7 +66,7 @@ def _vesync_brightness_to_ha(vesync_brightness):
|
||||
"VeSync - received unexpected 'brightness' value from pyvesync api: %s",
|
||||
vesync_brightness,
|
||||
)
|
||||
return 0
|
||||
return None
|
||||
# convert percent brightness to ha expected range
|
||||
return round((max(1, brightness_value) / 100) * 255)
|
||||
|
||||
@ -197,13 +197,13 @@ class VeSyncTunableWhiteLightHA(VeSyncBaseLight, LightEntity):
|
||||
return [COLOR_MODE_COLOR_TEMP]
|
||||
|
||||
|
||||
class VeSyncHumidifierNightLightHA(VeSyncDimmableLightHA):
|
||||
"""Representation of the night light on a VeSync humidifier."""
|
||||
class VeSyncNightLightHA(VeSyncDimmableLightHA):
|
||||
"""Representation of the night light on a VeSync device."""
|
||||
|
||||
def __init__(self, humidifier):
|
||||
"""Initialize the VeSync humidifier device."""
|
||||
super().__init__(humidifier)
|
||||
self.smarthumidifier = humidifier
|
||||
def __init__(self, device):
|
||||
"""Initialize the VeSync device."""
|
||||
super().__init__(device)
|
||||
self.device = device
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
@ -218,18 +218,19 @@ class VeSyncHumidifierNightLightHA(VeSyncDimmableLightHA):
|
||||
@property
|
||||
def brightness(self):
|
||||
"""Get night light brightness."""
|
||||
# get value from pyvesync library api,
|
||||
return _vesync_brightness_to_ha(
|
||||
self.smarthumidifier.details["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
|
||||
)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return True if night light is on."""
|
||||
if self.device.config_dict["module"] == "VeSyncAirBypass":
|
||||
return self.smarthumidifier.details["night_light"] == "on"
|
||||
else:
|
||||
return self.smarthumidifier.details["night_light_brightness"] > 0
|
||||
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_brightness"] > 0
|
||||
|
||||
@property
|
||||
def entity_category(self):
|
||||
@ -238,17 +239,17 @@ class VeSyncHumidifierNightLightHA(VeSyncDimmableLightHA):
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the night light on."""
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
if self.device.config_dict["module"] == "VeSyncAirBypass":
|
||||
self.device.set_night_light("on")
|
||||
elif ATTR_BRIGHTNESS in kwargs:
|
||||
brightness = _ha_brightness_to_vesync(kwargs[ATTR_BRIGHTNESS])
|
||||
self.smarthumidifier.set_night_light_brightness(brightness)
|
||||
elif self.device.config_dict["module"] == "VeSyncAirBypass":
|
||||
self.smarthumidifier.set_night_light("on")
|
||||
self.device.set_night_light_brightness(brightness)
|
||||
else:
|
||||
self.smarthumidifier.set_night_light_brightness(100)
|
||||
self.device.set_night_light_brightness(100)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the night light off."""
|
||||
if self.device.config_dict["module"] == "VeSyncAirBypass":
|
||||
self.smarthumidifier.set_night_light("off")
|
||||
self.device.set_night_light("off")
|
||||
else:
|
||||
self.smarthumidifier.set_night_light_brightness(0)
|
||||
self.device.set_night_light_brightness(0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user