Add sleepy device support to govee-ble (#122085)

This commit is contained in:
J. Nick Koston 2024-07-21 09:38:00 -05:00 committed by GitHub
parent 7e82b3ecdb
commit 39068bb786
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View file

@ -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

View file

@ -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