Add sleepy device support to govee-ble (#122085)
This commit is contained in:
parent
7e82b3ecdb
commit
39068bb786
2 changed files with 16 additions and 4 deletions
|
@ -10,6 +10,7 @@ from homeassistant.components.bluetooth import (
|
||||||
BluetoothServiceInfoBleak,
|
BluetoothServiceInfoBleak,
|
||||||
)
|
)
|
||||||
from homeassistant.components.bluetooth.passive_update_processor import (
|
from homeassistant.components.bluetooth.passive_update_processor import (
|
||||||
|
PassiveBluetoothDataProcessor,
|
||||||
PassiveBluetoothProcessorCoordinator,
|
PassiveBluetoothProcessorCoordinator,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
@ -77,3 +78,11 @@ class GoveeBLEBluetoothProcessorCoordinator(
|
||||||
def set_model_info(self, device_type: str) -> None:
|
def set_model_info(self, device_type: str) -> None:
|
||||||
"""Set the model info."""
|
"""Set the model info."""
|
||||||
self.model_info = get_model_info(device_type)
|
self.model_info = get_model_info(device_type)
|
||||||
|
|
||||||
|
|
||||||
|
class GoveeBLEPassiveBluetoothDataProcessor[_T](
|
||||||
|
PassiveBluetoothDataProcessor[_T, SensorUpdate]
|
||||||
|
):
|
||||||
|
"""Define a govee-ble Bluetooth Passive Update Data Processor."""
|
||||||
|
|
||||||
|
coordinator: GoveeBLEBluetoothProcessorCoordinator
|
||||||
|
|
|
@ -27,7 +27,7 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
|
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
|
||||||
|
|
||||||
from .coordinator import GoveeBLEConfigEntry
|
from .coordinator import GoveeBLEConfigEntry, GoveeBLEPassiveBluetoothDataProcessor
|
||||||
|
|
||||||
SENSOR_DESCRIPTIONS = {
|
SENSOR_DESCRIPTIONS = {
|
||||||
(DeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription(
|
(DeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription(
|
||||||
|
@ -130,12 +130,15 @@ class GoveeBluetoothSensorEntity(
|
||||||
):
|
):
|
||||||
"""Representation of a govee ble sensor."""
|
"""Representation of a govee ble sensor."""
|
||||||
|
|
||||||
|
processor: GoveeBLEPassiveBluetoothDataProcessor
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return False if sensor is in error."""
|
"""Return False if sensor is in error."""
|
||||||
return (
|
coordinator = self.processor.coordinator
|
||||||
self.processor.entity_data.get(self.entity_key) != ERROR
|
return self.processor.entity_data.get(self.entity_key) != ERROR and (
|
||||||
and super().available
|
((model_info := coordinator.model_info) and model_info.sleepy)
|
||||||
|
or super().available
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Add table
Reference in a new issue