mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Update homekit for new async library changes (#45731)
This commit is contained in:
parent
dac9626112
commit
852af7e372
@ -487,17 +487,17 @@ class HomeBridge(Bridge):
|
|||||||
def setup_message(self):
|
def setup_message(self):
|
||||||
"""Prevent print of pyhap setup message to terminal."""
|
"""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."""
|
"""Get snapshot from accessory if supported."""
|
||||||
acc = self.accessories.get(info["aid"])
|
acc = self.accessories.get(info["aid"])
|
||||||
if acc is None:
|
if acc is None:
|
||||||
raise ValueError("Requested snapshot for missing accessory")
|
raise ValueError("Requested snapshot for missing accessory")
|
||||||
if not hasattr(acc, "get_snapshot"):
|
if not hasattr(acc, "async_get_snapshot"):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Got a request for snapshot, but the Accessory "
|
"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):
|
class HomeDriver(AccessoryDriver):
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "HomeKit",
|
"name": "HomeKit",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/homekit",
|
"documentation": "https://www.home-assistant.io/integrations/homekit",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"HAP-python==3.1.0",
|
"HAP-python==3.2.0",
|
||||||
"fnvhash==0.1.0",
|
"fnvhash==0.1.0",
|
||||||
"PyQRCode==1.2.1",
|
"PyQRCode==1.2.1",
|
||||||
"base36==0.1.1",
|
"base36==0.1.1",
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Class to hold all camera accessories."""
|
"""Class to hold all camera accessories."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -444,13 +443,10 @@ class Camera(HomeAccessory, PyhapCamera):
|
|||||||
"""Reconfigure the stream so that it uses the given ``stream_config``."""
|
"""Reconfigure the stream so that it uses the given ``stream_config``."""
|
||||||
return True
|
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 a jpeg of a snapshot from the camera."""
|
||||||
return scale_jpeg_camera_image(
|
return scale_jpeg_camera_image(
|
||||||
asyncio.run_coroutine_threadsafe(
|
await self.hass.components.camera.async_get_image(self.entity_id),
|
||||||
self.hass.components.camera.async_get_image(self.entity_id),
|
|
||||||
self.hass.loop,
|
|
||||||
).result(),
|
|
||||||
image_size["image-width"],
|
image_size["image-width"],
|
||||||
image_size["image-height"],
|
image_size["image-height"],
|
||||||
)
|
)
|
||||||
|
@ -17,7 +17,7 @@ Adafruit-SHT31==1.0.2
|
|||||||
# Adafruit_BBIO==1.1.1
|
# Adafruit_BBIO==1.1.1
|
||||||
|
|
||||||
# homeassistant.components.homekit
|
# homeassistant.components.homekit
|
||||||
HAP-python==3.1.0
|
HAP-python==3.2.0
|
||||||
|
|
||||||
# homeassistant.components.mastodon
|
# homeassistant.components.mastodon
|
||||||
Mastodon.py==1.5.1
|
Mastodon.py==1.5.1
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
-r requirements_test.txt
|
-r requirements_test.txt
|
||||||
|
|
||||||
# homeassistant.components.homekit
|
# homeassistant.components.homekit
|
||||||
HAP-python==3.1.0
|
HAP-python==3.2.0
|
||||||
|
|
||||||
# homeassistant.components.flick_electric
|
# homeassistant.components.flick_electric
|
||||||
PyFlick==0.0.2
|
PyFlick==0.0.2
|
||||||
|
@ -212,22 +212,23 @@ async def test_camera_stream_source_configured(hass, run_driver, events):
|
|||||||
)
|
)
|
||||||
with patch("turbojpeg.TurboJPEG", return_value=turbo_jpeg):
|
with patch("turbojpeg.TurboJPEG", return_value=turbo_jpeg):
|
||||||
TurboJPEGSingleton()
|
TurboJPEGSingleton()
|
||||||
assert await hass.async_add_executor_job(
|
assert await acc.async_get_snapshot(
|
||||||
acc.get_snapshot, {"aid": 2, "image-width": 300, "image-height": 200}
|
{"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
|
# cameras and valid accessory ids
|
||||||
assert await hass.async_add_executor_job(
|
assert await bridge.async_get_snapshot(
|
||||||
bridge.get_snapshot, {"aid": 2, "image-width": 300, "image-height": 200}
|
{"aid": 2, "image-width": 300, "image-height": 200}
|
||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
assert await hass.async_add_executor_job(
|
assert await bridge.async_get_snapshot(
|
||||||
bridge.get_snapshot, {"aid": 3, "image-width": 300, "image-height": 200}
|
{"aid": 3, "image-width": 300, "image-height": 200}
|
||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
assert await hass.async_add_executor_job(
|
assert await bridge.async_get_snapshot(
|
||||||
bridge.get_snapshot, {"aid": 4, "image-width": 300, "image-height": 200}
|
{"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)
|
await _async_stop_all_streams(hass, acc)
|
||||||
|
|
||||||
with pytest.raises(HomeAssistantError):
|
with pytest.raises(HomeAssistantError):
|
||||||
await hass.async_add_executor_job(
|
assert await acc.async_get_snapshot(
|
||||||
acc.get_snapshot, {"aid": 2, "image-width": 300, "image-height": 200}
|
{"aid": 2, "image-width": 300, "image-height": 200}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user