1 """Support for fans through the SmartThings cloud API."""
3 from __future__
import annotations
5 from collections.abc
import Sequence
9 from pysmartthings
import Capability
16 percentage_to_ranged_value,
17 ranged_value_to_percentage,
21 from .const
import DATA_BROKERS, DOMAIN
22 from .entity
import SmartThingsEntity
29 config_entry: ConfigEntry,
30 async_add_entities: AddEntitiesCallback,
32 """Add fans for a config entry."""
33 broker = hass.data[DOMAIN][DATA_BROKERS][config_entry.entry_id]
36 for device
in broker.devices.values()
37 if broker.any_assigned(device.device_id,
"fan")
42 """Return all capabilities supported if minimum required are present."""
45 if Capability.switch
not in capabilities:
50 Capability.air_conditioner_fan_mode,
57 if not any(capability
in capabilities
for capability
in optional):
60 supported = [Capability.switch]
63 capability
for capability
in optional
if capability
in capabilities
70 """Define a SmartThings Fan."""
73 _enable_turn_on_off_backwards_compatibility =
False
81 flags = FanEntityFeature.TURN_OFF | FanEntityFeature.TURN_ON
84 flags |= FanEntityFeature.SET_SPEED
86 flags |= FanEntityFeature.PRESET_MODE
91 """Set the speed percentage of the fan."""
95 if percentage
is None:
96 await self.
_device_device.switch_on(set_status=
True)
98 await self.
_device_device.switch_off(set_status=
True)
101 await self.
_device_device.set_fan_speed(value, set_status=
True)
107 """Set the preset_mode of the fan."""
108 await self.
_device_device.set_fan_mode(preset_mode, set_status=
True)
113 percentage: int |
None =
None,
114 preset_mode: str |
None =
None,
117 """Turn the fan on."""
123 await self.
_device_device.switch_on(set_status=
True)
129 """Turn the fan off."""
130 await self.
_device_device.switch_off(set_status=
True)
137 """Return true if fan is on."""
138 return self.
_device_device.status.switch
142 """Return the current speed percentage."""
147 """Return the current preset mode, e.g., auto, smart, interval, favorite.
149 Requires FanEntityFeature.PRESET_MODE.
151 return self.
_device_device.status.fan_mode
155 """Return a list of available preset modes.
157 Requires FanEntityFeature.PRESET_MODE.
159 return self.
_device_device.status.supported_ac_fan_modes
int|None percentage(self)
None _async_set_percentage(self, int|None percentage)
None async_set_preset_mode(self, str preset_mode)
str|None preset_mode(self)
None async_turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
def _determine_features(self)
def __init__(self, device)
list[str]|None preset_modes(self)
None async_set_percentage(self, int percentage)
None async_turn_off(self, **Any kwargs)
None async_write_ha_state(self)
Sequence[str]|None get_capabilities(Sequence[str] capabilities)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Any|None get_capability(HomeAssistant hass, str entity_id, str capability)
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)