Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add an alias to the control panel and binary sensor entities #49

Merged
merged 29 commits into from
Sep 25, 2023
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fe60bfc
Update config_flow.py
xtimmy86x Sep 21, 2023
f7a30c7
Update strings.json
xtimmy86x Sep 21, 2023
3dadddb
Update it.json
xtimmy86x Sep 21, 2023
49c56a8
Update en.json
xtimmy86x Sep 21, 2023
98dc170
Update const.py
xtimmy86x Sep 21, 2023
2d5bd2e
Update alarm_control_panel.py
xtimmy86x Sep 21, 2023
207871d
Update binary_sensor.py
xtimmy86x Sep 21, 2023
18e7a10
Update manifest.json
xtimmy86x Sep 25, 2023
f064552
Update alarm_control_panel.py
xtimmy86x Sep 25, 2023
ced07b5
Update binary_sensor.py
xtimmy86x Sep 25, 2023
4a76bd8
Update config_flow.py
xtimmy86x Sep 25, 2023
a5e71ec
Update const.py
xtimmy86x Sep 25, 2023
ac9d1d1
Update strings.json
xtimmy86x Sep 25, 2023
6e3ae04
Update en.json
xtimmy86x Sep 25, 2023
7a5d59f
Update it.json
xtimmy86x Sep 25, 2023
91470ce
Update helpers.py
xtimmy86x Sep 25, 2023
c8ae35c
Update helpers.py
xtimmy86x Sep 25, 2023
b92b001
Update binary_sensor.py
xtimmy86x Sep 25, 2023
a1e9811
Update helpers.py
xtimmy86x Sep 25, 2023
a249eaf
chore: lint contributors code
palazzem Sep 25, 2023
bbff4c3
Update test_helpers.py
xtimmy86x Sep 25, 2023
ff8bd8a
Update test_helpers.py
xtimmy86x Sep 25, 2023
b1a4cbd
Update test_helpers.py
xtimmy86x Sep 25, 2023
a84545c
Update helpers.py
xtimmy86x Sep 25, 2023
4edb1d6
Update conftest.py
xtimmy86x Sep 25, 2023
7541141
Update test_helpers.py
xtimmy86x Sep 25, 2023
fe88066
Update test_helpers.py
xtimmy86x Sep 25, 2023
37d555f
Update helpers.py
xtimmy86x Sep 25, 2023
49b4ac3
chore: lint contributors code
palazzem Sep 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update binary_sensor.py
xtimmy86x authored and palazzem committed Sep 25, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit ced07b5bf4fbe580ee6b1ffd76c916354751b597
39 changes: 6 additions & 33 deletions custom_components/elmo_iess_alarm/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
from elmo import query
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_USERNAME, CONF_ALIAS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
@@ -13,15 +12,14 @@
from custom_components.elmo_iess_alarm.devices import AlarmDevice

from .const import DOMAIN, KEY_COORDINATOR, KEY_DEVICE

from .helpers import generate_entity_name

async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up e-connect binary sensors from a config entry."""

device = hass.data[DOMAIN][entry.entry_id][KEY_DEVICE]
coordinator = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR]
# Load all entities and register sectors and inputs
@@ -31,38 +29,13 @@ async def async_setup_entry(
inventory = await hass.async_add_executor_job(device._connection._get_descriptions)
for sector_id, name in inventory[query.SECTORS].items():
unique_id = f"{entry.entry_id}_{DOMAIN}_{query.SECTORS}_{sector_id}"

# Check if there is an alias in configuration flow and use it for naming
if "alias" in entry.data:
name_alias = f"{entry.data[CONF_ALIAS]} {name}"
else:
name_alias = f"{entry.data[CONF_USERNAME]} {name}"

sensors.append(EconnectDoorWindowSensor(coordinator, device, unique_id, sector_id, query.SECTORS, name_alias))
entity_name = f"{generate_entity_name(entry)} {name}"
sensors.append(EconnectDoorWindowSensor(coordinator, device, unique_id, sector_id, query.SECTORS, entity_name))

for sensor_id, name in inventory[query.INPUTS].items():
unique_id = f"{entry.entry_id}_{DOMAIN}_{query.INPUTS}_{sensor_id}"

# Check if there is an alias in configuration flow and use it for naming
if "alias" in entry.data:
name_alias = f"{entry.data[CONF_ALIAS]} {name}"
else:
name_alias = f"{entry.data[CONF_USERNAME]} {name}"

sensors.append(EconnectDoorWindowSensor(coordinator, device, unique_id, sensor_id, query.INPUTS, name_alias))

# Retrieve alarm system global status
alerts = await hass.async_add_executor_job(device._connection.get_status)
for name, value in alerts.items():
unique_id = f"{entry.entry_id}_{name}"

# Check if there is an alias in configuration flow and use it for naming
if "alias" in entry.data:
name_alias = f"{entry.data[CONF_ALIAS]} {name}"
else:
name_alias = f"{entry.data[CONF_USERNAME]} {name}"

sensors.append(EconnectAlertSensor(coordinator, unique_id, name_alias, value))
entity_name = f"{generate_entity_name(entry)} {name}"
sensors.append(EconnectDoorWindowSensor(coordinator, device, unique_id, sensor_id, query.INPUTS, entity_name))

async_add_entities(sensors)

@@ -85,7 +58,7 @@ def __init__(
self._unique_id = unique_id
self._sensor_id = sensor_id
self._sensor_type = sensor_type
self._name = name
self._name =name

@property
def unique_id(self) -> str: