Update homekit for new async library changes (#45731)

This commit is contained in:
J. Nick Koston 2021-01-31 10:40:24 -10:00 committed by GitHub
parent dac9626112
commit 852af7e372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 24 deletions

View File

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

View File

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

View File

@ -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"],
)

View File

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

View File

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

View File

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