1 """The Washer/Dryer Sensor for Whirlpool Appliances."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from datetime
import datetime, timedelta
10 from whirlpool.washerdryer
import MachineState, WasherDryer
16 SensorEntityDescription,
26 from .
import WhirlpoolData
27 from .const
import DOMAIN
39 MachineState.Standby:
"standby",
40 MachineState.Setting:
"setting",
41 MachineState.DelayCountdownMode:
"delay_countdown",
42 MachineState.DelayPause:
"delay_paused",
43 MachineState.SmartDelay:
"smart_delay",
44 MachineState.SmartGridPause:
"smart_grid_pause",
45 MachineState.Pause:
"pause",
46 MachineState.RunningMainCycle:
"running_maincycle",
47 MachineState.RunningPostCycle:
"running_postcycle",
48 MachineState.Exceptions:
"exception",
49 MachineState.Complete:
"complete",
50 MachineState.PowerFailure:
"power_failure",
51 MachineState.ServiceDiagnostic:
"service_diagnostic_mode",
52 MachineState.FactoryDiagnostic:
"factory_diagnostic_mode",
53 MachineState.LifeTest:
"life_test",
54 MachineState.CustomerFocusMode:
"customer_focus_mode",
55 MachineState.DemoMode:
"demo_mode",
56 MachineState.HardStopOrError:
"hard_stop_or_error",
57 MachineState.SystemInit:
"system_initialize",
61 (WasherDryer.get_cycle_status_filling,
"cycle_filling"),
62 (WasherDryer.get_cycle_status_rinsing,
"cycle_rinsing"),
63 (WasherDryer.get_cycle_status_sensing,
"cycle_sensing"),
64 (WasherDryer.get_cycle_status_soaking,
"cycle_soaking"),
65 (WasherDryer.get_cycle_status_spinning,
"cycle_spinning"),
66 (WasherDryer.get_cycle_status_washing,
"cycle_washing"),
69 DOOR_OPEN =
"door_open"
70 ICON_D =
"mdi:tumble-dryer"
71 ICON_W =
"mdi:washing-machine"
73 _LOGGER = logging.getLogger(__name__)
78 """Determine correct states for a washer."""
80 if washer.get_attribute(
"Cavity_OpStatusDoorOpen") ==
"1":
83 machine_state = washer.get_machine_state()
85 if machine_state == MachineState.RunningMainCycle:
86 for func, cycle_name
in CYCLE_FUNC:
90 return MACHINE_STATE.get(machine_state)
93 @dataclass(frozen=True, kw_only=True)
95 """Describes Whirlpool Washer sensor entity."""
100 SENSORS: tuple[WhirlpoolSensorEntityDescription, ...] = (
103 translation_key=
"whirlpool_machine",
104 device_class=SensorDeviceClass.ENUM,
106 list(MACHINE_STATE.values())
107 + [value
for _, value
in CYCLE_FUNC]
110 value_fn=washer_state,
114 translation_key=
"whirlpool_tank",
115 entity_registry_enabled_default=
False,
116 device_class=SensorDeviceClass.ENUM,
117 options=
list(TANK_FILL.values()),
118 value_fn=
lambda WasherDryer: TANK_FILL.get(
119 WasherDryer.get_attribute(
"WashCavity_OpStatusBulkDispense1Level")
124 SENSOR_TIMER: tuple[SensorEntityDescription] = (
127 translation_key=
"end_time",
128 device_class=SensorDeviceClass.TIMESTAMP,
135 config_entry: ConfigEntry,
136 async_add_entities: AddEntitiesCallback,
138 """Config flow entry for Whrilpool Laundry."""
140 whirlpool_data: WhirlpoolData = hass.data[DOMAIN][config_entry.entry_id]
141 for appliance
in whirlpool_data.appliances_manager.washer_dryers:
143 whirlpool_data.backend_selector,
158 for description
in SENSORS
169 for description
in SENSOR_TIMER
176 """A class for the whirlpool/maytag washer account."""
178 _attr_should_poll =
False
179 _attr_has_entity_name =
True
185 description: WhirlpoolSensorEntityDescription,
186 washdry: WasherDryer,
188 """Initialize the washer sensor."""
189 self._wd: WasherDryer = washdry
196 self.entity_description: WhirlpoolSensorEntityDescription = description
198 identifiers={(DOMAIN, said)},
199 name=name.capitalize(),
200 manufacturer=
"Whirlpool",
205 """Connect washer/dryer to the cloud."""
209 """Close Whirlpool Appliance sockets before removing."""
214 """Return True if entity is available."""
215 return self._wd.get_online()
219 """Return native value of sensor."""
220 return self.entity_description.
value_fn(self._wd)
224 """A timestamp class for the whirlpool/maytag washer account."""
226 _attr_should_poll =
True
227 _attr_has_entity_name =
True
233 description: SensorEntityDescription,
234 washdry: WasherDryer,
236 """Initialize the washer sensor."""
237 self._wd: WasherDryer = washdry
244 self.entity_description: SensorEntityDescription = description
245 self.
_running_running: bool |
None =
None
247 identifiers={(DOMAIN, said)},
248 name=name.capitalize(),
249 manufacturer=
"Whirlpool",
254 """Connect washer/dryer to the cloud."""
261 """Close Whrilpool Appliance sockets before removing."""
263 await self._wd.disconnect()
267 """Return True if entity is available."""
268 return self._wd.get_online()
271 """Update status of Whirlpool."""
276 """Calculate the time stamp for completion."""
277 machine_state = self._wd.get_machine_state()
281 in {MachineState.Complete.value, MachineState.Standby.value}
288 if machine_state
is MachineState.RunningMainCycle:
292 seconds=
int(self._wd.get_attribute(
"Cavity_TimeStatusEstTimeRemaining"))
SensorExtraStoredData|None async_get_last_sensor_data(self)
StateType|str native_value(self)
None async_will_remove_from_hass(self)
None async_added_to_hass(self)
None __init__(self, str said, str name, WhirlpoolSensorEntityDescription description, WasherDryer washdry)
None async_will_remove_from_hass(self)
None update_from_latest_data(self)
None async_added_to_hass(self)
None __init__(self, str said, str name, SensorEntityDescription description, WasherDryer washdry)
None _async_write_ha_state(self)
None async_write_ha_state(self)
MetOfficeData fetch_data(datapoint.Manager connection, Site site, str mode)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
str|None washer_state(WasherDryer washer)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)