Skip to content

Commit

Permalink
Add binary sensor name in config and allow multiple HDO signals
Browse files Browse the repository at this point in the history
  • Loading branch information
JKubovy committed Jan 11, 2023
1 parent a5e789f commit 83c49a8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion custom_components/predistribuce/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

DOMAIN = "predistribuce"
CONF_CMD = "receiver_command_id"
CONF_SENSOR_NAME = "sensor_name"
CONF_PERIODS = "periods"
CONF_NAME = "name"
CONF_MINUTES = "minutes"
Expand Down Expand Up @@ -54,16 +55,18 @@
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_CMD): cv.string,
vol.Optional(CONF_SENSOR_NAME): cv.string,
vol.Optional(CONF_PERIODS): vol.All(cv.ensure_list, [PERIOD_SCHEMA])
}
)


def setup_platform(hass, config, add_entities, discovery_info=None):
conf_cmd = config.get(CONF_CMD)
conf_name = config.get(CONF_SENSOR_NAME, "aktuálně")
conf_periods = config.get(CONF_PERIODS, [])
ents = []
ents.append(PreDistribuce(conf_cmd, 0, "HDO aktuálně"))
ents.append(PreDistribuce(conf_cmd, 0, conf_name))
for pre in conf_periods:
ents.append(PreDistribuce(conf_cmd, pre.get(CONF_MINUTES), pre.get(CONF_NAME)))
add_entities(ents)
Expand All @@ -74,6 +77,9 @@ def __init__(self, conf_cmd, minutes, name):
"""Initialize the sensor."""
self.conf_cmd = conf_cmd
self.minutes = minutes
self.entity_id = f"binary_sensor.hdo_{conf_cmd}"
self._attr_unique_id = f"{DOMAIN}-hbo-{conf_cmd}"
self._name = f"HBO {name}"
self._name = name
self.timeToNT = 0
self.html = "<div><i>Není spojení</i></div>"
Expand Down

0 comments on commit 83c49a8

Please sign in to comment.