Skip to content

Commit

Permalink
Merge pull request #39 from tomasbedrich/cancel-call
Browse files Browse the repository at this point in the history
Add cancel call button
  • Loading branch information
tomasbedrich committed Aug 25, 2023
2 parents c5c377f + d51ea14 commit 59c2d82
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 21 deletions.
18 changes: 0 additions & 18 deletions DEBUGGING.md

This file was deleted.

58 changes: 58 additions & 0 deletions custom_components/hikconnect/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import logging

from hikconnect.api import HikConnect
from homeassistant.components.button import ButtonEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
data = hass.data[DOMAIN]
api, coordinator = data["api"], data["coordinator"]

new_entities = []
for device_info in coordinator.data:
new_entities.append(CancelCallButton(api, device_info))

if new_entities:
async_add_entities(new_entities, update_before_add=True)


class CancelCallButton(ButtonEntity):
"""
Represents a cancel call operation of an indoor station.
"""

def __init__(self, api: HikConnect, device_info: dict):
super().__init__()
self._api = api
self._device_info = device_info

async def async_press(self) -> None:
await self._api.cancel_call(self._device_info["serial"])

@property
def name(self):
return f"{self._device_info['name']} cancel call" # TODO translate?

@property
def unique_id(self):
return "-".join((DOMAIN, self._device_info["id"], "cancel-call"))

@property
def device_info(self):
# https://developers.home-assistant.io/docs/device_registry_index/#device-properties
return {
"identifiers": {(DOMAIN, self._device_info["id"])},
}

@property
def icon(self):
return "mdi:phone-hangup"
2 changes: 1 addition & 1 deletion custom_components/hikconnect/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DOMAIN = "hikconnect"
MANUFACTURER = "Hikvision"
PLATFORMS = ["lock", "sensor"]
PLATFORMS = ["lock", "sensor", "button"]
4 changes: 2 additions & 2 deletions custom_components/hikconnect/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"hikconnect"
],
"requirements": [
"hikconnect==1.0.0"
"hikconnect==1.1.0"
],
"version": "2.0.1"
"version": "2.1.1"
}

0 comments on commit 59c2d82

Please sign in to comment.