Add support for bridge accessory unavailability (#52207)
Co-authored-by: Jc2k <john.carr@unrouted.co.uk>
This commit is contained in:
parent
0680e9f833
commit
562212bb5e
2 changed files with 29 additions and 1 deletions
|
@ -142,7 +142,7 @@ class HomeKitEntity(Entity):
|
|||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return self._accessory.available
|
||||
return self._accessory.available and self.service.available
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Basic checks for HomeKit sensor."""
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
from aiohomekit.protocol.statuscodes import HapStatusCode
|
||||
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_BATTERY,
|
||||
|
@ -236,3 +237,30 @@ async def test_switch_with_sensor(hass, utcnow):
|
|||
realtime_energy.value = 50
|
||||
state = await energy_helper.poll_and_get_state()
|
||||
assert state.state == "50"
|
||||
|
||||
|
||||
async def test_sensor_unavailable(hass, utcnow):
|
||||
"""Test a sensor becoming unavailable."""
|
||||
helper = await setup_test_component(hass, create_switch_with_sensor)
|
||||
|
||||
# Find the energy sensor and mark it as offline
|
||||
outlet = helper.accessory.services.first(service_type=ServicesTypes.OUTLET)
|
||||
realtime_energy = outlet[CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY]
|
||||
realtime_energy.status = HapStatusCode.UNABLE_TO_COMMUNICATE
|
||||
|
||||
# Helper will be for the primary entity, which is the outlet. Make a helper for the sensor.
|
||||
energy_helper = Helper(
|
||||
hass,
|
||||
"sensor.testdevice_real_time_energy",
|
||||
helper.pairing,
|
||||
helper.accessory,
|
||||
helper.config_entry,
|
||||
)
|
||||
|
||||
# Outlet has non-responsive characteristics so should be unavailable
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == "unavailable"
|
||||
|
||||
# Energy sensor has non-responsive characteristics so should be unavailable
|
||||
state = await energy_helper.poll_and_get_state()
|
||||
assert state.state == "unavailable"
|
||||
|
|
Loading…
Add table
Reference in a new issue