-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from tomasbedrich/cancel-call
Add cancel call button
- Loading branch information
Showing
4 changed files
with
61 additions
and
21 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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,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" |
This file contains 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
DOMAIN = "hikconnect" | ||
MANUFACTURER = "Hikvision" | ||
PLATFORMS = ["lock", "sensor"] | ||
PLATFORMS = ["lock", "sensor", "button"] |
This file contains 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