Skip to content

Commit

Permalink
Update with new api name and official hass changes. (#151)
Browse files Browse the repository at this point in the history
* Update with new python api library and changes from home assistant core. 
   - Includes encryption support for image entity.
* Add option to fetch camera password.
  • Loading branch information
RenierM26 authored Dec 30, 2024
1 parent 0232584 commit 853a28a
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 119 deletions.
4 changes: 2 additions & 2 deletions custom_components/ezviz_cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import logging

from pyezviz.client import EzvizClient
from pyezviz.exceptions import (
from pyezvizapi.client import EzvizClient
from pyezvizapi.exceptions import (
EzvizAuthTokenExpired,
EzvizAuthVerificationCode,
HTTPError,
Expand Down
26 changes: 11 additions & 15 deletions custom_components/ezviz_cloud/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@
from datetime import timedelta
import logging

from pyezviz import PyEzvizError
from pyezviz.constants import DefenseModeType
from pyezvizapi import PyEzvizError
from pyezvizapi.constants import DefenseModeType

from homeassistant.components.alarm_control_panel import (
AlarmControlPanelEntity,
AlarmControlPanelEntityDescription,
AlarmControlPanelEntityFeature,
AlarmControlPanelState,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
STATE_ALARM_ARMED_AWAY,
STATE_ALARM_ARMED_HOME,
STATE_ALARM_DISARMED,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.device_registry import DeviceInfo
Expand All @@ -45,9 +41,9 @@ class EzvizAlarmControlPanelEntityDescription(AlarmControlPanelEntityDescription
key="ezviz_alarm",
ezviz_alarm_states=[
None,
STATE_ALARM_DISARMED,
STATE_ALARM_ARMED_AWAY,
STATE_ALARM_ARMED_HOME,
AlarmControlPanelState.DISARMED,
AlarmControlPanelState.ARMED_AWAY,
AlarmControlPanelState.ARMED_HOME,
],
)

Expand Down Expand Up @@ -96,7 +92,7 @@ def __init__(
self._attr_device_info = device_info
self.entity_description = entity_description
self.coordinator = coordinator
self._attr_state = None
self._attr_alarm_state = None

async def async_added_to_hass(self) -> None:
"""Entity added to hass."""
Expand All @@ -108,7 +104,7 @@ def alarm_disarm(self, code: str | None = None) -> None:
if self.coordinator.ezviz_client.api_set_defence_mode(
DefenseModeType.HOME_MODE.value
):
self._attr_state = STATE_ALARM_DISARMED
self._attr_alarm_state = AlarmControlPanelState.DISARMED

except PyEzvizError as err:
raise HomeAssistantError("Cannot disarm EZVIZ alarm") from err
Expand All @@ -119,7 +115,7 @@ def alarm_arm_away(self, code: str | None = None) -> None:
if self.coordinator.ezviz_client.api_set_defence_mode(
DefenseModeType.AWAY_MODE.value
):
self._attr_state = STATE_ALARM_ARMED_AWAY
self._attr_alarm_state = AlarmControlPanelState.ARMED_AWAY

except PyEzvizError as err:
raise HomeAssistantError("Cannot arm EZVIZ alarm") from err
Expand All @@ -130,7 +126,7 @@ def alarm_arm_home(self, code: str | None = None) -> None:
if self.coordinator.ezviz_client.api_set_defence_mode(
DefenseModeType.SLEEP_MODE.value
):
self._attr_state = STATE_ALARM_ARMED_HOME
self._attr_alarm_state = AlarmControlPanelState.ARMED_HOME

except PyEzvizError as err:
raise HomeAssistantError("Cannot arm EZVIZ alarm") from err
Expand All @@ -145,7 +141,7 @@ def update(self) -> None:
_LOGGER.debug(
"Updating EZVIZ alarm with response %s", ezviz_alarm_state_number
)
self._attr_state = self.entity_description.ezviz_alarm_states[
self._attr_alarm_state = self.entity_description.ezviz_alarm_states[
int(ezviz_alarm_state_number)
]

Expand Down
6 changes: 3 additions & 3 deletions custom_components/ezviz_cloud/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from dataclasses import dataclass
from typing import Any

from pyezviz import EzvizClient
from pyezviz.constants import SupportExt
from pyezviz.exceptions import HTTPError, PyEzvizError
from pyezvizapi import EzvizClient
from pyezvizapi.constants import SupportExt
from pyezvizapi.exceptions import HTTPError, PyEzvizError

from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
from homeassistant.config_entries import ConfigEntry
Expand Down
4 changes: 2 additions & 2 deletions custom_components/ezviz_cloud/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging

from pyezviz.exceptions import HTTPError, InvalidHost, PyEzvizError
from pyezvizapi.exceptions import HTTPError, InvalidHost, PyEzvizError

from homeassistant.components import ffmpeg
from homeassistant.components.camera import Camera, CameraEntityFeature
Expand Down Expand Up @@ -112,7 +112,7 @@ async def async_setup_entry(
platform = async_get_current_platform()

platform.async_register_entity_service(
SERVICE_WAKE_DEVICE, {}, "perform_wake_device"
SERVICE_WAKE_DEVICE, None, "perform_wake_device"
)


Expand Down
Loading

0 comments on commit 853a28a

Please sign in to comment.