1 """Support for VeSync fans."""
3 from __future__
import annotations
15 percentage_to_ranged_value,
16 ranged_value_to_percentage,
20 from .const
import DEV_TYPE_TO_HA, DOMAIN, SKU_TO_BASE_DEVICE, VS_DISCOVERY, VS_FANS
21 from .entity
import VeSyncDevice
23 _LOGGER = logging.getLogger(__name__)
25 FAN_MODE_AUTO =
"auto"
26 FAN_MODE_SLEEP =
"sleep"
28 FAN_MODE_TURBO =
"turbo"
31 "LV-PUR131S": [FAN_MODE_AUTO, FAN_MODE_SLEEP],
32 "Core200S": [FAN_MODE_SLEEP],
33 "Core300S": [FAN_MODE_AUTO, FAN_MODE_SLEEP],
34 "Core400S": [FAN_MODE_AUTO, FAN_MODE_SLEEP],
35 "Core600S": [FAN_MODE_AUTO, FAN_MODE_SLEEP],
36 "EverestAir": [FAN_MODE_AUTO, FAN_MODE_SLEEP, FAN_MODE_TURBO],
37 "Vital200S": [FAN_MODE_AUTO, FAN_MODE_SLEEP, FAN_MODE_PET],
38 "Vital100S": [FAN_MODE_AUTO, FAN_MODE_SLEEP, FAN_MODE_PET],
54 config_entry: ConfigEntry,
55 async_add_entities: AddEntitiesCallback,
57 """Set up the VeSync fan platform."""
61 """Add new devices to platform."""
64 config_entry.async_on_unload(
73 """Check if device is online and add entity."""
76 if DEV_TYPE_TO_HA.get(SKU_TO_BASE_DEVICE.get(dev.device_type)) ==
"fan":
80 "%s - Unknown device type - %s", dev.device_name, dev.device_type
88 """Representation of a VeSync fan."""
90 _attr_supported_features = (
91 FanEntityFeature.SET_SPEED
92 | FanEntityFeature.PRESET_MODE
93 | FanEntityFeature.TURN_OFF
94 | FanEntityFeature.TURN_ON
97 _attr_translation_key =
"vesync"
98 _enable_turn_on_off_backwards_compatibility =
False
101 """Initialize the VeSync fan device."""
107 """Return the current speed."""
109 self.
smartfansmartfan.mode ==
"manual"
110 and (current_level := self.
smartfansmartfan.fan_level)
is not None
113 SPEED_RANGE[SKU_TO_BASE_DEVICE[self.
devicedevice.device_type]], current_level
119 """Return the number of speeds the fan supports."""
121 SPEED_RANGE[SKU_TO_BASE_DEVICE[self.
devicedevice.device_type]]
126 """Get the list of available preset modes."""
127 return PRESET_MODES[SKU_TO_BASE_DEVICE[self.
devicedevice.device_type]]
131 """Get the current preset mode."""
132 if self.
smartfansmartfan.mode
in (FAN_MODE_AUTO, FAN_MODE_SLEEP, FAN_MODE_TURBO):
138 """Return the ID of this fan."""
143 """Return the state attributes of the fan."""
146 if hasattr(self.
smartfansmartfan,
"active_time"):
147 attr[
"active_time"] = self.
smartfansmartfan.active_time
149 if hasattr(self.
smartfansmartfan,
"screen_status"):
150 attr[
"screen_status"] = self.
smartfansmartfan.screen_status
152 if hasattr(self.
smartfansmartfan,
"child_lock"):
153 attr[
"child_lock"] = self.
smartfansmartfan.child_lock
155 if hasattr(self.
smartfansmartfan,
"night_light"):
156 attr[
"night_light"] = self.
smartfansmartfan.night_light
158 if hasattr(self.
smartfansmartfan,
"mode"):
159 attr[
"mode"] = self.
smartfansmartfan.mode
164 """Set the speed of the device."""
173 self.
smartfansmartfan.change_fan_speed(
176 SPEED_RANGE[SKU_TO_BASE_DEVICE[self.
devicedevice.device_type]], percentage
183 """Set the preset mode of device."""
186 f
"{preset_mode} is not one of the valid preset modes: "
187 f
"{self.preset_modes}"
193 if preset_mode == FAN_MODE_AUTO:
195 elif preset_mode == FAN_MODE_SLEEP:
197 elif preset_mode == FAN_MODE_PET:
199 elif preset_mode == FAN_MODE_TURBO:
206 percentage: int |
None =
None,
207 preset_mode: str |
None =
None,
210 """Turn the device on."""
214 if percentage
is None:
None set_preset_mode(self, str preset_mode)
None set_percentage(self, int percentage)
list[str]|None preset_modes(self)
None turn_off(self, **Any kwargs)
dict[str, Any] extra_state_attributes(self)
str|None preset_mode(self)
int|None percentage(self)
None set_percentage(self, int percentage)
None set_preset_mode(self, str preset_mode)
None turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
list[str] preset_modes(self)
None schedule_update_ha_state(self, bool force_refresh=False)
list[tuple[str, int]] discover(HomeAssistant hass)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
def _setup_entities(devices, async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
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)