-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Event entity for login with wrong code
- Loading branch information
Showing
14 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
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
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
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,63 @@ | ||
from __future__ import annotations | ||
from homeassistant.components.event import ( | ||
EventEntity, | ||
EventEntityDescription, | ||
) | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import callback, HomeAssistant | ||
from homeassistant.helpers.dispatcher import async_dispatcher_connect | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from typing import Dict | ||
from .const import ( | ||
DATA_JABLOTRON, | ||
DOMAIN, | ||
EntityType, | ||
EventLoginType, | ||
) | ||
from .jablotron import Jablotron, JablotronControl, JablotronEntity | ||
|
||
EVENT_TYPES: Dict[EntityType, EventEntityDescription] = { | ||
EntityType.EVENT_LOGIN: EventEntityDescription( | ||
key=EntityType.EVENT_LOGIN, | ||
translation_key="login", | ||
icon="mdi:login", | ||
event_types=[EventLoginType.WRONG_CODE.value], | ||
), | ||
} | ||
|
||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> None: | ||
jablotron_instance: Jablotron = hass.data[DOMAIN][config_entry.entry_id][DATA_JABLOTRON] | ||
|
||
@callback | ||
def add_entities() -> None: | ||
entities = [] | ||
|
||
for entity_type in EVENT_TYPES: | ||
for entity in jablotron_instance.entities[entity_type].values(): | ||
if entity.id not in jablotron_instance.hass_entities: | ||
entities.append(JablotronEventEntity(jablotron_instance, entity, EVENT_TYPES[entity_type])) | ||
|
||
async_add_entities(entities) | ||
|
||
add_entities() | ||
|
||
config_entry.async_on_unload( | ||
async_dispatcher_connect(hass, jablotron_instance.signal_entities_added(), add_entities) | ||
) | ||
|
||
class JablotronEventEntity(JablotronEntity, EventEntity): | ||
|
||
def __init__( | ||
self, | ||
jablotron: Jablotron, | ||
control: JablotronControl, | ||
description: EventEntityDescription, | ||
) -> None: | ||
self.entity_description = description | ||
|
||
super().__init__(jablotron, control) | ||
|
||
def trigger_event(self, event: EventLoginType) -> None: | ||
self._trigger_event(event.value) | ||
self.async_write_ha_state() |
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
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
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
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
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
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
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
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
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
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
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,9 +1,8 @@ | ||
{ | ||
"name": "Jablotron 100", | ||
"content_in_root": false, | ||
"domains": ["alarm_control_panel", "binary_sensor", "sensor", "switch"], | ||
"domains": ["alarm_control_panel", "binary_sensor", "event", "sensor", "switch"], | ||
"country": ["CS", "DA", "DE", "EN", "IT", "NB", "NL", "SK"], | ||
"homeassistant": "2023.8.0", | ||
"render_readme": true | ||
} | ||
|