1 """Support for WeMo switches."""
3 from __future__
import annotations
5 from datetime
import datetime, timedelta
8 from pywemo
import CoffeeMaker, Insight, Maker, StandbyState, Switch
16 from .
import async_wemo_dispatcher_connect
17 from .coordinator
import DeviceCoordinator
18 from .entity
import WemoBinaryStateEntity
23 ATTR_COFFEMAKER_MODE =
"coffeemaker_mode"
24 ATTR_CURRENT_STATE_DETAIL =
"state_detail"
25 ATTR_ON_LATEST_TIME =
"on_latest_time"
26 ATTR_ON_TODAY_TIME =
"on_today_time"
27 ATTR_ON_TOTAL_TIME =
"on_total_time"
28 ATTR_POWER_THRESHOLD =
"power_threshold_w"
29 ATTR_SENSOR_STATE =
"sensor_state"
30 ATTR_SWITCH_MODE =
"switch_mode"
32 MAKER_SWITCH_MOMENTARY =
"momentary"
33 MAKER_SWITCH_TOGGLE =
"toggle"
38 _config_entry: ConfigEntry,
39 async_add_entities: AddEntitiesCallback,
41 """Set up WeMo switches."""
43 async
def _discovered_wemo(coordinator: DeviceCoordinator) ->
None:
44 """Handle a discovered Wemo device."""
51 """Representation of a WeMo switch."""
58 """Return the state attributes of the device."""
59 attr: dict[str, Any] = {}
60 if isinstance(self.
wemowemowemo, Maker):
65 attr[ATTR_SENSOR_STATE] = STATE_OFF
67 attr[ATTR_SENSOR_STATE] = STATE_ON
71 attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_MOMENTARY
73 attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_TOGGLE
75 if isinstance(self.
wemowemowemo, (Insight, CoffeeMaker)):
76 attr[ATTR_CURRENT_STATE_DETAIL] = self.
detail_statedetail_state
78 if isinstance(self.
wemowemowemo, Insight):
80 attr[ATTR_ON_TODAY_TIME] = self.
as_uptimeas_uptime(self.
wemowemowemo.today_on_time)
81 attr[ATTR_ON_TOTAL_TIME] = self.
as_uptimeas_uptime(self.
wemowemowemo.total_on_time)
82 attr[ATTR_POWER_THRESHOLD] = self.
wemowemowemo.threshold_power_watts
84 if isinstance(self.
wemowemowemo, CoffeeMaker):
85 attr[ATTR_COFFEMAKER_MODE] = self.
wemowemowemo.mode
91 """Format seconds into uptime string in the format: 00d 00h 00m 00s."""
94 f
"{uptime.day - 1:0>2d}d {uptime.hour:0>2d}h "
95 f
"{uptime.minute:0>2d}m {uptime.second:0>2d}s"
100 """Return the state of the device."""
101 if isinstance(self.
wemowemowemo, CoffeeMaker):
102 return self.
wemowemowemo.mode_string
103 if isinstance(self.
wemowemowemo, Insight):
104 standby_state = self.
wemowemowemo.standby_state
105 if standby_state == StandbyState.ON:
107 if standby_state == StandbyState.OFF:
109 if standby_state == StandbyState.STANDBY:
117 """Return the icon of device based on its type."""
118 if isinstance(self.
wemowemowemo, CoffeeMaker):
123 """Turn the switch on."""
128 """Turn the switch off."""
Generator[None] _wemo_call_wrapper(self, str message)
str as_uptime(int _seconds)
None turn_off(self, **Any kwargs)
dict[str, Any] extra_state_attributes(self)
None turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry _config_entry, AddEntitiesCallback async_add_entities)
None async_wemo_dispatcher_connect(HomeAssistant hass, DispatchCallback dispatch)
datetime_sys datetime(Any value)