diff --git a/homeassistant/components/homekit/accessories.py b/homeassistant/components/homekit/accessories.py index 3cd3c46613b..cb1c76656bb 100644 --- a/homeassistant/components/homekit/accessories.py +++ b/homeassistant/components/homekit/accessories.py @@ -25,6 +25,7 @@ from homeassistant.const import ( DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE, STATE_ON, + STATE_UNAVAILABLE, TEMP_CELSIUS, TEMP_FAHRENHEIT, UNIT_PERCENTAGE, @@ -322,6 +323,12 @@ class HomeAccessory(Accessory): CHAR_STATUS_LOW_BATTERY, value=0 ) + @property + def available(self): + """Return if accessory is available.""" + state = self.hass.states.get(self.entity_id) + return state is not None and state.state != STATE_UNAVAILABLE + async def run(self): """Handle accessory driver started event. diff --git a/homeassistant/components/homekit/manifest.json b/homeassistant/components/homekit/manifest.json index 8f7382b5d85..985fcc1e799 100644 --- a/homeassistant/components/homekit/manifest.json +++ b/homeassistant/components/homekit/manifest.json @@ -2,7 +2,7 @@ "domain": "homekit", "name": "HomeKit", "documentation": "https://www.home-assistant.io/integrations/homekit", - "requirements": ["HAP-python==2.8.4","fnvhash==0.1.0","PyQRCode==1.2.1","base36==0.1.1","PyTurboJPEG==1.4.0"], + "requirements": ["HAP-python==2.9.1","fnvhash==0.1.0","PyQRCode==1.2.1","base36==0.1.1","PyTurboJPEG==1.4.0"], "dependencies": ["http", "camera", "ffmpeg"], "after_dependencies": ["logbook", "zeroconf"], "codeowners": ["@bdraco"], diff --git a/requirements_all.txt b/requirements_all.txt index a8aff04a190..90a2a87df1f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -35,7 +35,7 @@ Adafruit-SHT31==1.0.2 # Adafruit_BBIO==1.1.1 # homeassistant.components.homekit -HAP-python==2.8.4 +HAP-python==2.9.1 # homeassistant.components.mastodon Mastodon.py==1.5.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 79516cf84bc..c30e6745cbc 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -4,7 +4,7 @@ -r requirements_test.txt # homeassistant.components.homekit -HAP-python==2.8.4 +HAP-python==2.9.1 # homeassistant.components.plugwise Plugwise_Smile==0.2.10 diff --git a/tests/components/homekit/test_accessories.py b/tests/components/homekit/test_accessories.py index 092c68a5480..abc6d9b5528 100644 --- a/tests/components/homekit/test_accessories.py +++ b/tests/components/homekit/test_accessories.py @@ -42,6 +42,7 @@ from homeassistant.const import ( EVENT_TIME_CHANGED, STATE_OFF, STATE_ON, + STATE_UNAVAILABLE, __version__, ) import homeassistant.util.dt as dt_util @@ -88,7 +89,7 @@ async def test_home_accessory(hass, hk_driver): entity_id2 = "light.accessory" hass.states.async_set(entity_id, None) - hass.states.async_set(entity_id2, None) + hass.states.async_set(entity_id2, STATE_UNAVAILABLE) await hass.async_block_till_done() @@ -98,6 +99,7 @@ async def test_home_accessory(hass, hk_driver): assert acc.hass == hass assert acc.display_name == "Home Accessory" assert acc.aid == 2 + assert acc.available is True assert acc.category == 1 # Category.OTHER assert len(acc.services) == 1 serv = acc.services[0] # SERV_ACCESSORY_INFO @@ -127,6 +129,7 @@ async def test_home_accessory(hass, hk_driver): ATTR_INTERGRATION: "luxe", }, ) + assert acc3.available is False serv = acc3.services[0] # SERV_ACCESSORY_INFO assert serv.get_characteristic(CHAR_NAME).value == "Home Accessory" assert serv.get_characteristic(CHAR_MANUFACTURER).value == "Lux Brands"