1 """An abstract class common to all Switchbot entities."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from switchbot
import Switchbot, SwitchbotDevice
12 PassiveBluetoothCoordinatorEntity,
20 from .const
import MANUFACTURER
21 from .coordinator
import SwitchbotDataUpdateCoordinator
23 _LOGGER = logging.getLogger(__name__)
27 PassiveBluetoothCoordinatorEntity[SwitchbotDataUpdateCoordinator]
29 """Generic entity encapsulating common features of Switchbot device."""
31 _device: SwitchbotDevice
32 _attr_has_entity_name =
True
34 def __init__(self, coordinator: SwitchbotDataUpdateCoordinator) ->
None:
35 """Initialize the entity."""
38 self._last_run_success: bool |
None =
None
39 self.
_address_address = coordinator.ble_device.address
42 connections={(dr.CONNECTION_BLUETOOTH, self.
_address_address)},
43 manufacturer=MANUFACTURER,
44 model=coordinator.model,
45 name=coordinator.device_name,
55 (dr.CONNECTION_NETWORK_MAC, self.
_address_address)
60 """Return parsed device data for this entity."""
61 return self.coordinator.device.parsed_data
65 """Return the state attributes."""
66 return {
"last_run_success": self._last_run_success}
70 """Update the entity attributes."""
74 """Handle data update."""
76 self.async_write_ha_state()
79 """Register callbacks."""
86 Only used by the generic entity update service.
92 """Base class for Switchbot entities that can be turned on and off."""
98 _LOGGER.debug(
"Turn Switchbot device on %s", self.
_address_address)
106 """Turn device off."""
107 _LOGGER.debug(
"Turn Switchbot device off %s", self.
_address_address)
None _handle_coordinator_update(self)
Mapping[Any, Any] extra_state_attributes(self)
None async_added_to_hass(self)
dict[str, Any] parsed_data(self)
None __init__(self, SwitchbotDataUpdateCoordinator coordinator)
None _async_update_attrs(self)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_write_ha_state(self)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
bool add(self, _T matcher)
Callable[[], None] subscribe(HomeAssistant hass, str topic, MessageCallbackType msg_callback, int qos=DEFAULT_QOS, str encoding="utf-8")