diff --git a/homeassistant/components/homekit/accessories.py b/homeassistant/components/homekit/accessories.py index 571c47a521b..6a33b63e89a 100644 --- a/homeassistant/components/homekit/accessories.py +++ b/homeassistant/components/homekit/accessories.py @@ -487,17 +487,17 @@ class HomeBridge(Bridge): def setup_message(self): """Prevent print of pyhap setup message to terminal.""" - def get_snapshot(self, info): + async def async_get_snapshot(self, info): """Get snapshot from accessory if supported.""" acc = self.accessories.get(info["aid"]) if acc is None: raise ValueError("Requested snapshot for missing accessory") - if not hasattr(acc, "get_snapshot"): + if not hasattr(acc, "async_get_snapshot"): raise ValueError( "Got a request for snapshot, but the Accessory " - 'does not define a "get_snapshot" method' + 'does not define a "async_get_snapshot" method' ) - return acc.get_snapshot(info) + return await acc.async_get_snapshot(info) class HomeDriver(AccessoryDriver): diff --git a/homeassistant/components/homekit/manifest.json b/homeassistant/components/homekit/manifest.json index d188dd270ab..23b43958848 100644 --- a/homeassistant/components/homekit/manifest.json +++ b/homeassistant/components/homekit/manifest.json @@ -3,7 +3,7 @@ "name": "HomeKit", "documentation": "https://www.home-assistant.io/integrations/homekit", "requirements": [ - "HAP-python==3.1.0", + "HAP-python==3.2.0", "fnvhash==0.1.0", "PyQRCode==1.2.1", "base36==0.1.1", diff --git a/homeassistant/components/homekit/type_cameras.py b/homeassistant/components/homekit/type_cameras.py index b61a2c57612..22bf37aa0c3 100644 --- a/homeassistant/components/homekit/type_cameras.py +++ b/homeassistant/components/homekit/type_cameras.py @@ -1,5 +1,4 @@ """Class to hold all camera accessories.""" -import asyncio from datetime import timedelta import logging @@ -444,13 +443,10 @@ class Camera(HomeAccessory, PyhapCamera): """Reconfigure the stream so that it uses the given ``stream_config``.""" return True - def get_snapshot(self, image_size): + async def async_get_snapshot(self, image_size): """Return a jpeg of a snapshot from the camera.""" return scale_jpeg_camera_image( - asyncio.run_coroutine_threadsafe( - self.hass.components.camera.async_get_image(self.entity_id), - self.hass.loop, - ).result(), + await self.hass.components.camera.async_get_image(self.entity_id), image_size["image-width"], image_size["image-height"], ) diff --git a/requirements_all.txt b/requirements_all.txt index a8127ed7097..8281744f221 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -17,7 +17,7 @@ Adafruit-SHT31==1.0.2 # Adafruit_BBIO==1.1.1 # homeassistant.components.homekit -HAP-python==3.1.0 +HAP-python==3.2.0 # homeassistant.components.mastodon Mastodon.py==1.5.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 3e8972c9864..d997b91f338 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -4,7 +4,7 @@ -r requirements_test.txt # homeassistant.components.homekit -HAP-python==3.1.0 +HAP-python==3.2.0 # homeassistant.components.flick_electric PyFlick==0.0.2 diff --git a/tests/components/homekit/test_type_cameras.py b/tests/components/homekit/test_type_cameras.py index 804e03a4e6c..f4c7169310f 100644 --- a/tests/components/homekit/test_type_cameras.py +++ b/tests/components/homekit/test_type_cameras.py @@ -212,22 +212,23 @@ async def test_camera_stream_source_configured(hass, run_driver, events): ) with patch("turbojpeg.TurboJPEG", return_value=turbo_jpeg): TurboJPEGSingleton() - assert await hass.async_add_executor_job( - acc.get_snapshot, {"aid": 2, "image-width": 300, "image-height": 200} + assert await acc.async_get_snapshot( + {"aid": 2, "image-width": 300, "image-height": 200} ) - # Verify the bridge only forwards get_snapshot for + # Verify the bridge only forwards async_get_snapshot for # cameras and valid accessory ids - assert await hass.async_add_executor_job( - bridge.get_snapshot, {"aid": 2, "image-width": 300, "image-height": 200} + assert await bridge.async_get_snapshot( + {"aid": 2, "image-width": 300, "image-height": 200} ) with pytest.raises(ValueError): - assert await hass.async_add_executor_job( - bridge.get_snapshot, {"aid": 3, "image-width": 300, "image-height": 200} + assert await bridge.async_get_snapshot( + {"aid": 3, "image-width": 300, "image-height": 200} ) + with pytest.raises(ValueError): - assert await hass.async_add_executor_job( - bridge.get_snapshot, {"aid": 4, "image-width": 300, "image-height": 200} + assert await bridge.async_get_snapshot( + {"aid": 4, "image-width": 300, "image-height": 200} ) @@ -400,8 +401,8 @@ async def test_camera_with_no_stream(hass, run_driver, events): await _async_stop_all_streams(hass, acc) with pytest.raises(HomeAssistantError): - await hass.async_add_executor_job( - acc.get_snapshot, {"aid": 2, "image-width": 300, "image-height": 200} + assert await acc.async_get_snapshot( + {"aid": 2, "image-width": 300, "image-height": 200} )