Skip to content

Commit

Permalink
Support more states for main camera entity (#201)
Browse files Browse the repository at this point in the history
* Add state to frigate camera

* Use correct key

* Use direct const instead of HASS const

* Update custom_components/frigate/camera.py

Co-authored-by: Dermot Duffy <dermot.duffy@gmail.com>

* Use recording attribute

* Use similar safe method for streaming check

* Resolve review comments

* Resolve review comments

* Use attr_streaming

* Adjust test to catch Streaming enabled

* streaming captilization error

Co-authored-by: Dermot Duffy <dermot.duffy@gmail.com>
  • Loading branch information
NickM-27 and dermotduffy committed Jan 14, 2022
1 parent 49805c7 commit 8e5b7d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions custom_components/frigate/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def __init__(
self._cam_name = cam_name
self._camera_config = camera_config
self._url = config_entry.data[CONF_URL]
self._stream_enabled = self._camera_config["rtmp"]["enabled"]
self._attr_is_streaming = self._camera_config.get("rtmp", {}).get("enabled")
self._attr_is_recording = self._camera_config.get("record", {}).get("enabled")

streaming_template = config_entry.options.get(
CONF_RTMP_URL_TEMPLATE, ""
Expand Down Expand Up @@ -116,7 +117,7 @@ def device_info(self) -> dict[str, Any]:
@property
def supported_features(self) -> int:
"""Return supported features of this camera."""
if not self._stream_enabled:
if not self._attr_is_streaming:
return 0
return cast(int, SUPPORT_STREAM)

Expand All @@ -138,7 +139,7 @@ async def async_camera_image(

async def stream_source(self) -> str | None:
"""Return the source of the stream."""
if not self._stream_enabled:
if not self._attr_is_streaming:
return None
return self._stream_source

Expand Down
2 changes: 1 addition & 1 deletion tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def test_frigate_camera_setup(

entity_state = hass.states.get(TEST_CAMERA_FRONT_DOOR_ENTITY_ID)
assert entity_state
assert entity_state.state == "idle"
assert entity_state.state == "streaming"
assert entity_state.attributes["supported_features"] == 2

source = await async_get_stream_source(hass, TEST_CAMERA_FRONT_DOOR_ENTITY_ID)
Expand Down

0 comments on commit 8e5b7d4

Please sign in to comment.