1 """Classes shared among Wemo entities."""
3 from __future__
import annotations
5 from collections.abc
import Generator
9 from pywemo.exceptions
import ActionException
14 from .coordinator
import DeviceCoordinator
16 _LOGGER = logging.getLogger(__name__)
20 """Common methods for Wemo entities."""
25 _name_suffix: str |
None =
None
26 _unique_id_suffix: str |
None =
None
28 def __init__(self, coordinator: DeviceCoordinator) ->
None:
29 """Initialize the WeMo device."""
36 """Suffix to append to the WeMo device name."""
37 return self._name_suffix
41 """Return the name of the device if any."""
42 wemo_name: str = self.
wemowemowemo.name
44 return f
"{wemo_name} {suffix}"
49 """Suffix to append to the WeMo device's unique ID."""
50 if self._unique_id_suffix
is None and self.
name_suffixname_suffix
is not None:
52 return self._unique_id_suffix
56 """Return the id of this WeMo device."""
57 serial_number: str = self.
wemowemowemo.serial_number
59 return f
"{serial_number}_{suffix}"
64 """Return the device info."""
67 @contextlib.contextmanager
69 """Wrap calls to the device that change its state.
71 1. Takes care of making available=False when communications with the
73 2. Ensures all entities sharing the same coordinator are aware of
74 updates to the device state.
78 except ActionException
as err:
79 _LOGGER.warning(
"Could not %s for %s (%s)", message, self.
namenamename, err)
80 self.coordinator.last_exception = err
81 self.coordinator.last_update_success =
False
83 self.
hasshasshass.add_job(self.coordinator.async_update_listeners)
87 """Base for devices that return on/off state via device.get_state()."""
91 """Return true if the state is on."""
str|None unique_id_suffix(self)
Generator[None] _wemo_call_wrapper(self, str message)
None __init__(self, DeviceCoordinator coordinator)
str|None name_suffix(self)
str|float get_state(dict[str, float] data, str key)