Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for new devices #5

Merged
merged 5 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions custom_components/vesync/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def _setup_entities(devices, async_add_entities, coordinator):
entities.append(VeSyncOutOfWaterSensor(dev, coordinator))
if has_feature(dev, "details", "water_tank_lifted"):
entities.append(VeSyncWaterTankLiftedSensor(dev, coordinator))
if has_feature(dev, "details", "filter_open_state"):
entities.append(VeSyncFilterOpenStateSensor(dev, coordinator))

async_add_entities(entities, update_before_add=True)

Expand Down Expand Up @@ -148,3 +150,22 @@ def name(self):
def is_on(self) -> bool:
"""Return a value indicating whether the Humidifier's water tank is lifted."""
return self.smarthumidifier.details["water_tank_lifted"]


class VeSyncFilterOpenStateSensor(VeSyncBinarySensorEntity):
"""Filter Open Sensor."""

@property
def unique_id(self):
"""Return unique ID for filter open state sensor on device."""
return f"{super().unique_id}-filter-open-state"

@property
def name(self):
"""Return sensor name."""
return f"{super().name} filter open state"

@property
def is_on(self) -> bool:
"""Return a value indicating whether the Humidifier's filter is open."""
return self.smarthumidifier.details["filter_open_state"]
2 changes: 1 addition & 1 deletion custom_components/vesync/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def unique_id(self):
@property
def base_name(self):
"""Return the name of the device."""
return self.device.device_type
return self.device.device_name

@property
def name(self):
Expand Down
3 changes: 2 additions & 1 deletion custom_components/vesync/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
VS_MODE_HUMIDITY = "humidity"
VS_MODE_MANUAL = "manual"
VS_MODE_SLEEP = "sleep"
VS_MODE_TURBO = "turbo"

VS_TO_HA_ATTRIBUTES = {"humidity": "current_humidity"}

VS_FAN_TYPES = ["VeSyncAirBypass", "VeSyncAir131", "VeSyncVital"]
VS_FAN_TYPES = ["VeSyncAirBypass", "VeSyncAir131", "VeSyncAirBaseV2"]
VS_HUMIDIFIERS_TYPES = ["VeSyncHumid200300S", "VeSyncHumid200S", "VeSyncHumid1000S"]
VS_AIRFRYER_TYPES = ["VeSyncAirFryer158"]

Expand Down
13 changes: 8 additions & 5 deletions custom_components/vesync/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
VS_MODE_AUTO,
VS_MODE_MANUAL,
VS_MODE_SLEEP,
VS_MODE_TURBO,
VS_MODES,
VS_TO_HA_ATTRIBUTES,
)
Expand Down Expand Up @@ -69,15 +70,15 @@ def __init__(self, fan, coordinator) -> None:
self.smartfan = fan
self._speed_range = (1, 1)
self._attr_preset_modes = [VS_MODE_MANUAL, VS_MODE_AUTO, VS_MODE_SLEEP]
if has_feature(self.smartfan, "config_dict", VS_LEVELS):
self._speed_range = (1, max(self.smartfan.config_dict[VS_LEVELS]))
if has_feature(self.smartfan, "config_dict", VS_MODES):
if has_feature(self.smartfan, "_config_dict", VS_LEVELS):
self._speed_range = (1, max(self.smartfan._config_dict[VS_LEVELS]))
if has_feature(self.smartfan, "_config_dict", VS_MODES):
self._attr_preset_modes = [
VS_MODE_MANUAL,
*[
mode
for mode in [VS_MODE_AUTO, VS_MODE_SLEEP]
if mode in self.smartfan.config_dict[VS_MODES]
for mode in [VS_MODE_AUTO, VS_MODE_SLEEP, VS_MODE_TURBO]
if mode in self.smartfan._config_dict[VS_MODES]
],
]
if self.smartfan.device_type == "LV-PUR131S":
Expand Down Expand Up @@ -161,6 +162,8 @@ def set_preset_mode(self, preset_mode):
self.smartfan.sleep_mode()
elif preset_mode == VS_MODE_MANUAL:
self.smartfan.manual_mode()
elif preset_mode == VS_MODE_TURBO:
self.smartfan.turbo_mode()

self.schedule_update_ha_state()

Expand Down
6 changes: 3 additions & 3 deletions custom_components/vesync/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .common import VeSyncDevice, has_feature
from .const import DEV_TYPE_TO_HA, DOMAIN, VS_DISCOVERY, VS_LIGHTS
from .const import DEV_TYPE_TO_HA, DOMAIN, VS_DISCOVERY, VS_FAN_TYPES, VS_LIGHTS

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -255,7 +255,7 @@ def entity_category(self):

def turn_on(self, **kwargs):
"""Turn the night light on."""
if self.device.config_dict["module"] == "VeSyncAirBypass":
if self.device._config_dict["module"] in VS_FAN_TYPES:
if ATTR_BRIGHTNESS in kwargs and kwargs[ATTR_BRIGHTNESS] < 255:
self.device.set_night_light("dim")
else:
Expand All @@ -269,7 +269,7 @@ def turn_on(self, **kwargs):

def turn_off(self, **kwargs):
"""Turn the night light off."""
if self.device.config_dict["module"] == "VeSyncAirBypass":
if self.device._config_dict["module"] in VS_FAN_TYPES:
self.device.set_night_light("off")
else:
self.device.set_night_light_brightness(0)
8 changes: 4 additions & 4 deletions custom_components/vesync/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"macaddress": "*"
}
],
"documentation": "https://github.com/AndreaTomatis/custom_vesync",
"documentation": "https://github.com/micahqcade/custom_vesync",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/AndreaTomatis/custom_vesync",
"issue_tracker": "https://github.com/micahqcade/custom_vesync",
"requirements": [
"pyvesync==2.1.10"
"pyvesync==2.1.12"
],
"version": "1.3.1"
"version": "1.3.2"
}
20 changes: 10 additions & 10 deletions custom_components/vesync/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _setup_entities(devices, async_add_entities, coordinator):
entities.append(VeSyncHumidifierTargetLevelHA(dev, coordinator))
if has_feature(dev, "details", "warm_mist_level"):
entities.append(VeSyncHumidifierWarmthLevelHA(dev, coordinator))
if has_feature(dev, "config_dict", "levels"):
if has_feature(dev, "_config_dict", "levels"):
entities.append(VeSyncFanSpeedLevelHA(dev, coordinator))

async_add_entities(entities, update_before_add=True)
Expand All @@ -77,8 +77,8 @@ class VeSyncFanSpeedLevelHA(VeSyncNumberEntity):
def __init__(self, device, coordinator) -> None:
"""Initialize the number entity."""
super().__init__(device, coordinator)
self._attr_native_min_value = device.config_dict["levels"][0]
self._attr_native_max_value = device.config_dict["levels"][-1]
self._attr_native_min_value = device._config_dict["levels"][0]
self._attr_native_max_value = device._config_dict["levels"][-1]
self._attr_native_step = 1

@property
Expand All @@ -99,7 +99,7 @@ def native_value(self):
@property
def extra_state_attributes(self):
"""Return the state attributes of the humidifier."""
return {"fan speed levels": self.device.config_dict["levels"]}
return {"fan speed levels": self.device._config_dict["levels"]}

def set_native_value(self, value):
"""Set the fan speed level."""
Expand All @@ -112,8 +112,8 @@ class VeSyncHumidifierMistLevelHA(VeSyncNumberEntity):
def __init__(self, device, coordinator) -> None:
"""Initialize the number entity."""
super().__init__(device, coordinator)
self._attr_native_min_value = device.config_dict["mist_levels"][0]
self._attr_native_max_value = device.config_dict["mist_levels"][-1]
self._attr_native_min_value = device._config_dict["mist_levels"][0]
self._attr_native_max_value = device._config_dict["mist_levels"][-1]
self._attr_native_step = 1

@property
Expand All @@ -134,7 +134,7 @@ def native_value(self):
@property
def extra_state_attributes(self):
"""Return the state attributes of the humidifier."""
return {"mist levels": self.device.config_dict["mist_levels"]}
return {"mist levels": self.device._config_dict["mist_levels"]}

def set_native_value(self, value):
"""Set the mist level."""
Expand All @@ -147,8 +147,8 @@ class VeSyncHumidifierWarmthLevelHA(VeSyncNumberEntity):
def __init__(self, device, coordinator) -> None:
"""Initialize the number entity."""
super().__init__(device, coordinator)
self._attr_native_min_value = device.config_dict["warm_mist_levels"][0]
self._attr_native_max_value = device.config_dict["warm_mist_levels"][-1]
self._attr_native_min_value = device._config_dict["warm_mist_levels"][0]
self._attr_native_max_value = device._config_dict["warm_mist_levels"][-1]
self._attr_native_step = 1

@property
Expand All @@ -169,7 +169,7 @@ def native_value(self):
@property
def extra_state_attributes(self):
"""Return the state attributes of the humidifier."""
return {"warm mist levels": self.device.config_dict["warm_mist_levels"]}
return {"warm mist levels": self.device._config_dict["warm_mist_levels"]}

def set_native_value(self, value):
"""Set the mist level."""
Expand Down
Loading