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,
|
||||
)
|
||||
from homeassistant.components.bluetooth.passive_update_processor import (
|
||||
PassiveBluetoothDataProcessor,
|
||||
PassiveBluetoothProcessorCoordinator,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -77,3 +78,11 @@ class GoveeBLEBluetoothProcessorCoordinator(
|
|||
def set_model_info(self, device_type: str) -> None:
|
||||
"""Set the model info."""
|
||||
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.sensor import sensor_device_info_to_hass_device_info
|
||||
|
||||
from .coordinator import GoveeBLEConfigEntry
|
||||
from .coordinator import GoveeBLEConfigEntry, GoveeBLEPassiveBluetoothDataProcessor
|
||||
|
||||
SENSOR_DESCRIPTIONS = {
|
||||
(DeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription(
|
||||
|
@ -130,12 +130,15 @@ class GoveeBluetoothSensorEntity(
|
|||
):
|
||||
"""Representation of a govee ble sensor."""
|
||||
|
||||
processor: GoveeBLEPassiveBluetoothDataProcessor
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return False if sensor is in error."""
|
||||
return (
|
||||
self.processor.entity_data.get(self.entity_key) != ERROR
|
||||
and super().available
|
||||
coordinator = self.processor.coordinator
|
||||
return self.processor.entity_data.get(self.entity_key) != ERROR and (
|
||||
((model_info := coordinator.model_info) and model_info.sleepy)
|
||||
or super().available
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Reference in a new issue