-
-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Initial camera support for homekit_controller #43100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """Support for Homekit cameras.""" | ||
| from aiohomekit.model.services import ServicesTypes | ||
|
|
||
| from homeassistant.components.camera import Camera | ||
| from homeassistant.core import callback | ||
|
|
||
| from . import KNOWN_DEVICES, AccessoryEntity | ||
|
|
||
|
|
||
| class HomeKitCamera(AccessoryEntity, Camera): | ||
| """Representation of a Homekit camera.""" | ||
|
|
||
| # content_type = "image/jpeg" | ||
|
|
||
| def get_characteristic_types(self): | ||
| """Define the homekit characteristics the entity is tracking.""" | ||
| return [] | ||
|
|
||
| @property | ||
| def state(self): | ||
| """Return the current state of the camera.""" | ||
| return "idle" | ||
|
|
||
| async def async_camera_image(self): | ||
| """Return a jpeg with the current camera snapshot.""" | ||
| return await self._accessory.pairing.image( | ||
| self._aid, | ||
| 640, | ||
| 480, | ||
| ) | ||
|
|
||
|
|
||
| async def async_setup_entry(hass, config_entry, async_add_entities): | ||
| """Set up Homekit sensors.""" | ||
| hkid = config_entry.data["AccessoryPairingID"] | ||
| conn = hass.data[KNOWN_DEVICES][hkid] | ||
|
|
||
| @callback | ||
| def async_add_accessory(accessory): | ||
| stream_mgmt = accessory.services.first( | ||
| service_type=ServicesTypes.CAMERA_RTP_STREAM_MANAGEMENT | ||
| ) | ||
| if not stream_mgmt: | ||
| return | ||
|
|
||
| info = {"aid": accessory.aid, "iid": stream_mgmt.iid} | ||
| async_add_entities([HomeKitCamera(conn, info)], True) | ||
| return True | ||
|
|
||
| conn.add_accessory_factory(async_add_accessory) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
tests/components/homekit_controller/specific_devices/test_anker_eufycam.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """Test against characteristics captured from a eufycam.""" | ||
|
|
||
| from tests.components.homekit_controller.common import ( | ||
| Helper, | ||
| setup_accessories_from_file, | ||
| setup_test_accessories, | ||
| ) | ||
|
|
||
|
|
||
| async def test_eufycam_setup(hass): | ||
| """Test that a eufycam can be correctly setup in HA.""" | ||
| accessories = await setup_accessories_from_file(hass, "anker_eufycam.json") | ||
| config_entry, pairing = await setup_test_accessories(hass, accessories) | ||
|
|
||
| entity_registry = await hass.helpers.entity_registry.async_get_registry() | ||
|
|
||
| # Check that the camera is correctly found and set up | ||
| camera_id = "camera.eufycam2_0000" | ||
| camera = entity_registry.async_get(camera_id) | ||
| assert camera.unique_id == "homekit-A0000A000000000D-aid:4" | ||
|
|
||
| camera_helper = Helper( | ||
| hass, | ||
| "camera.eufycam2_0000", | ||
| pairing, | ||
| accessories[0], | ||
| config_entry, | ||
| ) | ||
|
|
||
| camera_state = await camera_helper.poll_and_get_state() | ||
| assert camera_state.attributes["friendly_name"] == "eufyCam2-0000" | ||
| assert camera_state.state == "idle" | ||
| assert camera_state.attributes["supported_features"] == 0 | ||
|
|
||
| device_registry = await hass.helpers.device_registry.async_get_registry() | ||
|
|
||
| device = device_registry.async_get(camera.device_id) | ||
| assert device.manufacturer == "Anker" | ||
| assert device.name == "eufyCam2-0000" | ||
| assert device.model == "T8113" | ||
| assert device.sw_version == "1.6.7" | ||
|
|
||
| # These cameras are via a bridge, so via should be set | ||
| assert device.via_device_id is not None | ||
|
|
||
| cameras_count = 0 | ||
| for state in hass.states.async_all(): | ||
| if state.entity_id.startswith("camera."): | ||
| cameras_count += 1 | ||
|
|
||
| # There are multiple rtsp services, we only want to create 1 | ||
| # camera entity per accessory, not 1 camera per service. | ||
| assert cameras_count == 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| """Basic checks for HomeKit cameras.""" | ||
| import base64 | ||
|
|
||
| from aiohomekit.model.services import ServicesTypes | ||
| from aiohomekit.testing import FAKE_CAMERA_IMAGE | ||
|
|
||
| from homeassistant.components import camera | ||
|
|
||
| from tests.components.homekit_controller.common import setup_test_component | ||
|
|
||
|
|
||
| def create_camera(accessory): | ||
| """Define camera characteristics.""" | ||
| accessory.add_service(ServicesTypes.CAMERA_RTP_STREAM_MANAGEMENT) | ||
|
|
||
|
|
||
| async def test_read_state(hass, utcnow): | ||
| """Test reading the state of a HomeKit camera.""" | ||
| helper = await setup_test_component(hass, create_camera) | ||
|
|
||
| state = await helper.poll_and_get_state() | ||
| assert state.state == "idle" | ||
|
|
||
|
|
||
| async def test_get_image(hass, utcnow): | ||
| """Test getting a JPEG from a camera.""" | ||
| helper = await setup_test_component(hass, create_camera) | ||
| image = await camera.async_get_image(hass, helper.entity_id) | ||
| assert image.content == base64.b64decode(FAKE_CAMERA_IMAGE) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to mark the dependency upgrade in the MR template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course happy to do this, but the PR template says to only check 1 box.