Skip to content

Commit

Permalink
Only add PTZ buttons for PTZ cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
RenierM26 committed May 28, 2023
1 parent 141ac65 commit 35a58d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions custom_components/ezviz_cloud/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class EzvizButtonEntityDescriptionMixin:
"""Mixin values for EZVIZ button entities."""

method: Callable[[Any, Any, Any], Any]
supported_ext: str


@dataclass
Expand All @@ -37,39 +38,39 @@ class EzvizButtonEntityDescription(
BUTTON_ENTITIES = (
EzvizButtonEntityDescription(
key="ptz_up",
entity_registry_enabled_default=False,
name="PTZ up",
icon="mdi:pan",
method=lambda pyezviz_client, serial, run: pyezviz_client.ptz_control(
"UP", serial, run
),
supported_ext="154",
),
EzvizButtonEntityDescription(
key="ptz_down",
entity_registry_enabled_default=False,
name="PTZ down",
icon="mdi:pan",
method=lambda pyezviz_client, serial, run: pyezviz_client.ptz_control(
"DOWN", serial, run
),
supported_ext="154",
),
EzvizButtonEntityDescription(
key="ptz_left",
entity_registry_enabled_default=False,
name="PTZ left",
icon="mdi:pan",
method=lambda pyezviz_client, serial, run: pyezviz_client.ptz_control(
"LEFT", serial, run
),
supported_ext="154",
),
EzvizButtonEntityDescription(
key="ptz_right",
entity_registry_enabled_default=False,
name="PTZ right",
icon="mdi:pan",
method=lambda pyezviz_client, serial, run: pyezviz_client.ptz_control(
"RIGHT", serial, run
),
supported_ext="154",
),
)

Expand All @@ -85,7 +86,10 @@ async def async_setup_entry(
async_add_entities(
EzvizButton(coordinator, camera, entity_description)
for camera in coordinator.data
for capibility, value in coordinator.data[camera]["supportExt"].items()
for entity_description in BUTTON_ENTITIES
if capibility == entity_description.supported_ext
if value == "1"
)


Expand Down
4 changes: 2 additions & 2 deletions custom_components/ezviz_cloud/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"documentation": "https://www.home-assistant.io/integrations/ezviz",
"iot_class": "cloud_polling",
"loggers": ["paho_mqtt", "pyezviz"],
"requirements": ["pyezviz==0.2.0.12"],
"version": "0.1.0.11"
"requirements": ["pyezviz==0.2.0.14"],
"version": "0.1.0.12"
}

0 comments on commit 35a58d0

Please sign in to comment.