1 """Support for number entities."""
3 from __future__
import annotations
7 from thinqconnect
import DeviceType
8 from thinqconnect.devices.const
import Property
as ThinQProperty
9 from thinqconnect.integration
import ActiveMode, TimerProperty
14 NumberEntityDescription,
21 from .
import ThinqConfigEntry
22 from .entity
import ThinQEntity
24 NUMBER_DESC: dict[ThinQProperty, NumberEntityDescription] = {
26 key=ThinQProperty.FAN_SPEED,
27 translation_key=ThinQProperty.FAN_SPEED,
30 key=ThinQProperty.LAMP_BRIGHTNESS,
31 translation_key=ThinQProperty.LAMP_BRIGHTNESS,
34 key=ThinQProperty.LIGHT_STATUS,
35 native_unit_of_measurement=PERCENTAGE,
36 translation_key=ThinQProperty.LIGHT_STATUS,
39 key=ThinQProperty.TARGET_HUMIDITY,
40 device_class=NumberDeviceClass.HUMIDITY,
41 native_unit_of_measurement=PERCENTAGE,
42 translation_key=ThinQProperty.TARGET_HUMIDITY,
45 key=ThinQProperty.TARGET_TEMPERATURE,
46 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
47 translation_key=ThinQProperty.TARGET_TEMPERATURE,
50 key=ThinQProperty.WIND_TEMPERATURE,
51 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
52 translation_key=ThinQProperty.WIND_TEMPERATURE,
55 TIMER_NUMBER_DESC: dict[ThinQProperty, NumberEntityDescription] = {
57 key=ThinQProperty.RELATIVE_HOUR_TO_START,
58 native_unit_of_measurement=UnitOfTime.HOURS,
59 translation_key=ThinQProperty.RELATIVE_HOUR_TO_START,
62 key=ThinQProperty.RELATIVE_HOUR_TO_START,
64 native_unit_of_measurement=UnitOfTime.HOURS,
65 translation_key=TimerProperty.RELATIVE_HOUR_TO_START_WM,
68 key=ThinQProperty.RELATIVE_HOUR_TO_STOP,
69 native_unit_of_measurement=UnitOfTime.HOURS,
70 translation_key=ThinQProperty.RELATIVE_HOUR_TO_STOP,
73 key=ThinQProperty.RELATIVE_HOUR_TO_STOP,
75 native_unit_of_measurement=UnitOfTime.HOURS,
76 translation_key=TimerProperty.RELATIVE_HOUR_TO_STOP_WM,
79 key=ThinQProperty.SLEEP_TIMER_RELATIVE_HOUR_TO_STOP,
80 native_unit_of_measurement=UnitOfTime.HOURS,
81 translation_key=ThinQProperty.SLEEP_TIMER_RELATIVE_HOUR_TO_STOP,
84 WASHER_NUMBERS: tuple[NumberEntityDescription, ...] = (
85 TIMER_NUMBER_DESC[TimerProperty.RELATIVE_HOUR_TO_START_WM],
86 TIMER_NUMBER_DESC[TimerProperty.RELATIVE_HOUR_TO_STOP_WM],
89 DEVICE_TYPE_NUMBER_MAP: dict[DeviceType, tuple[NumberEntityDescription, ...]] = {
90 DeviceType.AIR_CONDITIONER: (
91 TIMER_NUMBER_DESC[ThinQProperty.RELATIVE_HOUR_TO_START],
92 TIMER_NUMBER_DESC[ThinQProperty.RELATIVE_HOUR_TO_STOP],
93 TIMER_NUMBER_DESC[ThinQProperty.SLEEP_TIMER_RELATIVE_HOUR_TO_STOP],
95 DeviceType.AIR_PURIFIER_FAN: (
96 NUMBER_DESC[ThinQProperty.WIND_TEMPERATURE],
97 TIMER_NUMBER_DESC[ThinQProperty.SLEEP_TIMER_RELATIVE_HOUR_TO_STOP],
99 DeviceType.DRYER: WASHER_NUMBERS,
101 NUMBER_DESC[ThinQProperty.LAMP_BRIGHTNESS],
102 NUMBER_DESC[ThinQProperty.FAN_SPEED],
104 DeviceType.HUMIDIFIER: (
105 NUMBER_DESC[ThinQProperty.TARGET_HUMIDITY],
106 TIMER_NUMBER_DESC[ThinQProperty.SLEEP_TIMER_RELATIVE_HOUR_TO_STOP],
108 DeviceType.MICROWAVE_OVEN: (
109 NUMBER_DESC[ThinQProperty.LAMP_BRIGHTNESS],
110 NUMBER_DESC[ThinQProperty.FAN_SPEED],
112 DeviceType.OVEN: (NUMBER_DESC[ThinQProperty.TARGET_TEMPERATURE],),
113 DeviceType.REFRIGERATOR: (NUMBER_DESC[ThinQProperty.TARGET_TEMPERATURE],),
114 DeviceType.STYLER: (TIMER_NUMBER_DESC[TimerProperty.RELATIVE_HOUR_TO_STOP_WM],),
115 DeviceType.WASHCOMBO_MAIN: WASHER_NUMBERS,
116 DeviceType.WASHCOMBO_MINI: WASHER_NUMBERS,
117 DeviceType.WASHER: WASHER_NUMBERS,
118 DeviceType.WASHTOWER_DRYER: WASHER_NUMBERS,
119 DeviceType.WASHTOWER: WASHER_NUMBERS,
120 DeviceType.WASHTOWER_WASHER: WASHER_NUMBERS,
121 DeviceType.WATER_HEATER: (
123 key=ThinQProperty.TARGET_TEMPERATURE,
127 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
128 translation_key=ThinQProperty.TARGET_TEMPERATURE,
131 DeviceType.WINE_CELLAR: (
132 NUMBER_DESC[ThinQProperty.LIGHT_STATUS],
133 NUMBER_DESC[ThinQProperty.TARGET_TEMPERATURE],
137 _LOGGER = logging.getLogger(__name__)
142 entry: ThinqConfigEntry,
143 async_add_entities: AddEntitiesCallback,
145 """Set up an entry for number platform."""
146 entities: list[ThinQNumberEntity] = []
147 for coordinator
in entry.runtime_data.coordinators.values():
149 descriptions := DEVICE_TYPE_NUMBER_MAP.get(
150 coordinator.api.device.device_type
153 for description
in descriptions:
156 for property_id
in coordinator.api.get_active_idx(
157 description.key, ActiveMode.READ_WRITE
166 """Represent a thinq number platform."""
168 _attr_mode = NumberMode.BOX
171 """Update status itself."""
185 and (min_value := self.
datadatadatadata.min)
is not None
191 and (max_value := self.
datadatadatadata.max)
is not None
202 "[%s:%s] update status: %s -> %s, unit:%s, min:%s, max:%s, step:%s",
203 self.coordinator.device_name,
214 """Change to new number value."""
215 if self.
stepstep.is_integer():
218 "[%s:%s] async_set_native_value: %s",
219 self.coordinator.device_name,
None async_call_api(self, Coroutine[Any, Any, Any] target, Callable[[], None]|None on_fail_method=None)
str|None _get_unit_of_measurement(self, str|None unit)
_attr_native_unit_of_measurement
None async_set_native_value(self, float value)
None _update_status(self)
str|None native_unit_of_measurement(self)
float|None native_step(self)
float native_min_value(self)
float|None native_value(self)
float native_max_value(self)
None async_setup_entry(HomeAssistant hass, ThinqConfigEntry entry, AddEntitiesCallback async_add_entities)