1 """Support for WeMo humidifier."""
3 from __future__
import annotations
5 from datetime
import timedelta
9 from pywemo
import DesiredHumidity, FanMode, Humidifier
10 import voluptuous
as vol
19 percentage_to_ranged_value,
20 ranged_value_to_percentage,
24 from .
import async_wemo_dispatcher_connect
25 from .const
import SERVICE_RESET_FILTER_LIFE, SERVICE_SET_HUMIDITY
26 from .coordinator
import DeviceCoordinator
27 from .entity
import WemoBinaryStateEntity
32 ATTR_CURRENT_HUMIDITY =
"current_humidity"
33 ATTR_TARGET_HUMIDITY =
"target_humidity"
34 ATTR_FAN_MODE =
"fan_mode"
35 ATTR_FILTER_LIFE =
"filter_life"
36 ATTR_FILTER_EXPIRED =
"filter_expired"
37 ATTR_WATER_LEVEL =
"water_level"
39 SPEED_RANGE = (FanMode.Minimum, FanMode.Maximum)
41 SET_HUMIDITY_SCHEMA: VolDictType = {
42 vol.Required(ATTR_TARGET_HUMIDITY): vol.All(
43 vol.Coerce(float), vol.Range(min=0, max=100)
50 _config_entry: ConfigEntry,
51 async_add_entities: AddEntitiesCallback,
53 """Set up WeMo binary sensors."""
55 async
def _discovered_wemo(coordinator: DeviceCoordinator) ->
None:
56 """Handle a discovered Wemo device."""
61 platform = entity_platform.async_get_current_platform()
64 platform.async_register_entity_service(
65 SERVICE_SET_HUMIDITY, SET_HUMIDITY_SCHEMA, WemoHumidifier.set_humidity.__name__
69 platform.async_register_entity_service(
70 SERVICE_RESET_FILTER_LIFE,
None, WemoHumidifier.reset_filter_life.__name__
75 """Representation of a WeMo humidifier."""
77 _attr_supported_features = (
78 FanEntityFeature.SET_SPEED
79 | FanEntityFeature.TURN_OFF
80 | FanEntityFeature.TURN_ON
83 _last_fan_on_mode: FanMode
84 _enable_turn_on_off_backwards_compatibility =
False
86 def __init__(self, coordinator: DeviceCoordinator) ->
None:
87 """Initialize the WeMo switch."""
89 if self.
wemowemowemo.fan_mode != FanMode.Off:
96 """Return the icon of device based on its type."""
97 return "mdi:water-percent"
101 """Return device specific state attributes."""
103 ATTR_CURRENT_HUMIDITY: self.
wemowemowemo.current_humidity_percent,
104 ATTR_TARGET_HUMIDITY: self.
wemowemowemo.desired_humidity_percent,
105 ATTR_FAN_MODE: self.
wemowemowemo.fan_mode_string,
106 ATTR_WATER_LEVEL: self.
wemowemowemo.water_level_string,
107 ATTR_FILTER_LIFE: self.
wemowemowemo.filter_life_percent,
108 ATTR_FILTER_EXPIRED: self.
wemowemowemo.filter_expired,
113 """Return the current speed percentage."""
118 """Return the number of speeds the fan supports."""
123 """Handle updated data from the coordinator."""
124 if self.
wemowemowemo.fan_mode != FanMode.Off:
130 percentage: int |
None =
None,
131 preset_mode: str |
None =
None,
134 """Turn the fan on."""
138 """Turn the switch off."""
140 self.
wemowemowemo.set_state(FanMode.Off)
143 """Set the fan_mode of the Humidifier."""
147 if percentage
is None:
149 elif percentage == 0:
150 named_speed = FanMode.Off
152 named_speed = FanMode(
157 self.
wemowemowemo.set_state(named_speed)
160 """Set the target humidity level for the Humidifier."""
161 if target_humidity < 50:
162 pywemo_humidity = DesiredHumidity.FortyFivePercent
163 elif 50 <= target_humidity < 55:
164 pywemo_humidity = DesiredHumidity.FiftyPercent
165 elif 55 <= target_humidity < 60:
166 pywemo_humidity = DesiredHumidity.FiftyFivePercent
167 elif 60 <= target_humidity < 100:
168 pywemo_humidity = DesiredHumidity.SixtyPercent
169 elif target_humidity >= 100:
170 pywemo_humidity = DesiredHumidity.OneHundredPercent
176 """Reset the filter life to 100%."""
Generator[None] _wemo_call_wrapper(self, str message)
None __init__(self, DeviceCoordinator coordinator)
None set_percentage(self, int percentage)
None turn_off(self, **Any kwargs)
None turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
None set_humidity(self, float target_humidity)
dict[str, Any] extra_state_attributes(self)
None reset_filter_life(self)
None _handle_coordinator_update(self)
None _set_percentage(self, int|None percentage)
None async_setup_entry(HomeAssistant hass, ConfigEntry _config_entry, AddEntitiesCallback async_add_entities)
None async_wemo_dispatcher_connect(HomeAssistant hass, DispatchCallback dispatch)
float percentage_to_ranged_value(tuple[float, float] low_high_range, float percentage)
int ranged_value_to_percentage(tuple[float, float] low_high_range, float value)
int int_states_in_range(tuple[float, float] low_high_range)