* Update switchbot to be local push * fixes * fixes * fixes * fixes * adjust * cover is not assumed anymore * cleanups * adjust * adjust * add missing cover * import compat * fixes * uses lower * uses lower * bleak users upper case addresses * fixes * bump * keep conf_mac and deprecated options for rollback * reuse coordinator * adjust * move around * move around * move around * move around * refactor fixes * compat with DataUpdateCoordinator * fix available * Update homeassistant/components/bluetooth/passive_update_processor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/bluetooth/passive_update_coordinator.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/bluetooth/update_coordinator.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Split bluetooth coordinator into PassiveBluetoothDataUpdateCoordinator and PassiveBluetoothProcessorCoordinator The PassiveBluetoothDataUpdateCoordinator is now used to replace instances of DataUpdateCoordinator where the data is coming from bluetooth advertisements, and the integration may also mix in active updates The PassiveBluetoothProcessorCoordinator is used for integrations that want to process each bluetooth advertisement with multiple processors which can be dispatched to individual platforms or areas or the integration as it chooes * change connections * reduce code churn to reduce review overhead * reduce code churn to reduce review overhead * Update homeassistant/components/bluetooth/passive_update_coordinator.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * add basic test * add basic test * complete coverage * Update homeassistant/components/switchbot/coordinator.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/switchbot/coordinator.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/switchbot/__init__.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/switchbot/__init__.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * lint Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
"""An abstract class common to all Switchbot entities."""
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from typing import Any
|
|
|
|
from homeassistant.components.bluetooth.passive_update_coordinator import (
|
|
PassiveBluetoothCoordinatorEntity,
|
|
)
|
|
from homeassistant.const import ATTR_CONNECTIONS
|
|
from homeassistant.helpers import device_registry as dr
|
|
from homeassistant.helpers.entity import DeviceInfo
|
|
|
|
from .const import MANUFACTURER
|
|
from .coordinator import SwitchbotDataUpdateCoordinator
|
|
|
|
|
|
class SwitchbotEntity(PassiveBluetoothCoordinatorEntity):
|
|
"""Generic entity encapsulating common features of Switchbot device."""
|
|
|
|
coordinator: SwitchbotDataUpdateCoordinator
|
|
|
|
def __init__(
|
|
self,
|
|
coordinator: SwitchbotDataUpdateCoordinator,
|
|
unique_id: str,
|
|
address: str,
|
|
name: str,
|
|
) -> None:
|
|
"""Initialize the entity."""
|
|
super().__init__(coordinator)
|
|
self._last_run_success: bool | None = None
|
|
self._unique_id = unique_id
|
|
self._address = address
|
|
self._attr_name = name
|
|
self._attr_device_info = DeviceInfo(
|
|
connections={(dr.CONNECTION_BLUETOOTH, self._address)},
|
|
manufacturer=MANUFACTURER,
|
|
model=self.data["modelName"],
|
|
name=name,
|
|
)
|
|
if ":" not in self._address:
|
|
# MacOS Bluetooth addresses are not mac addresses
|
|
return
|
|
# If the bluetooth address is also a mac address,
|
|
# add this connection as well to prevent a new device
|
|
# entry from being created when upgrading from a previous
|
|
# version of the integration.
|
|
self._attr_device_info[ATTR_CONNECTIONS].add(
|
|
(dr.CONNECTION_NETWORK_MAC, self._address)
|
|
)
|
|
|
|
@property
|
|
def data(self) -> dict[str, Any]:
|
|
"""Return coordinator data for this entity."""
|
|
return self.coordinator.data
|
|
|
|
@property
|
|
def extra_state_attributes(self) -> Mapping[Any, Any]:
|
|
"""Return the state attributes."""
|
|
return {"last_run_success": self._last_run_success}
|