mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Add ability to monitor relay events (#18730)
* Add ability to monitor relay events * Account for empty events array instead of none.
This commit is contained in:
parent
937688f7a6
commit
199db7219e
@ -25,6 +25,7 @@ API_URL = '/api/{}'.format(DOMAIN)
|
||||
CONF_CUSTOM_URL = 'hass_url_override'
|
||||
CONF_DOORBELL_EVENTS = 'doorbell_events'
|
||||
CONF_DOORBELL_NUMS = 'doorbell_numbers'
|
||||
CONF_RELAY_NUMS = 'relay_numbers'
|
||||
CONF_MOTION_EVENTS = 'motion_events'
|
||||
CONF_TOKEN = 'token'
|
||||
|
||||
@ -37,6 +38,10 @@ SENSOR_TYPES = {
|
||||
'name': 'Motion',
|
||||
'device_class': 'motion',
|
||||
},
|
||||
'relay': {
|
||||
'name': 'Relay',
|
||||
'device_class': 'relay',
|
||||
}
|
||||
}
|
||||
|
||||
RESET_DEVICE_FAVORITES = 'doorbird_reset_favorites'
|
||||
@ -47,6 +52,8 @@ DEVICE_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_DOORBELL_NUMS, default=[1]): vol.All(
|
||||
cv.ensure_list, [cv.positive_int]),
|
||||
vol.Optional(CONF_RELAY_NUMS, default=[1]): vol.All(
|
||||
cv.ensure_list, [cv.positive_int]),
|
||||
vol.Optional(CONF_CUSTOM_URL): cv.string,
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=[]):
|
||||
@ -80,6 +87,7 @@ def setup(hass, config):
|
||||
username = doorstation_config.get(CONF_USERNAME)
|
||||
password = doorstation_config.get(CONF_PASSWORD)
|
||||
doorbell_nums = doorstation_config.get(CONF_DOORBELL_NUMS)
|
||||
relay_nums = doorstation_config.get(CONF_RELAY_NUMS)
|
||||
custom_url = doorstation_config.get(CONF_CUSTOM_URL)
|
||||
events = doorstation_config.get(CONF_MONITORED_CONDITIONS)
|
||||
name = (doorstation_config.get(CONF_NAME)
|
||||
@ -90,7 +98,7 @@ def setup(hass, config):
|
||||
|
||||
if status[0]:
|
||||
doorstation = ConfiguredDoorBird(device, name, events, custom_url,
|
||||
doorbell_nums, token)
|
||||
doorbell_nums, relay_nums, token)
|
||||
doorstations.append(doorstation)
|
||||
_LOGGER.info('Connected to DoorBird "%s" as %s@%s',
|
||||
doorstation.name, username, device_ip)
|
||||
@ -148,13 +156,15 @@ def handle_event(event):
|
||||
class ConfiguredDoorBird():
|
||||
"""Attach additional information to pass along with configured device."""
|
||||
|
||||
def __init__(self, device, name, events, custom_url, doorbell_nums, token):
|
||||
def __init__(self, device, name, events, custom_url, doorbell_nums,
|
||||
relay_nums, token):
|
||||
"""Initialize configured device."""
|
||||
self._name = name
|
||||
self._device = device
|
||||
self._custom_url = custom_url
|
||||
self._monitored_events = events
|
||||
self._doorbell_nums = doorbell_nums
|
||||
self._relay_nums = relay_nums
|
||||
self._token = token
|
||||
|
||||
@property
|
||||
@ -218,9 +228,8 @@ class ConfiguredDoorBird():
|
||||
|
||||
# Register HA URL as webhook if not already, then get the ID
|
||||
if not self.webhook_is_registered(hass_url):
|
||||
self.device.change_favorite('http',
|
||||
'Home Assistant on {} ({} events)'
|
||||
.format(hass_url, event), hass_url)
|
||||
self.device.change_favorite('http', 'Home Assistant ({} events)'
|
||||
.format(event), hass_url)
|
||||
fav_id = self.get_webhook_id(hass_url)
|
||||
|
||||
if not fav_id:
|
||||
@ -239,6 +248,13 @@ class ConfiguredDoorBird():
|
||||
entry = self.device.get_schedule_entry(event, str(doorbell))
|
||||
entry.output.append(output)
|
||||
self.device.change_schedule(entry)
|
||||
elif event == 'relay':
|
||||
# Repeat edit for each monitored doorbell number
|
||||
for relay in self._relay_nums:
|
||||
entry = self.device.get_schedule_entry(event, str(relay))
|
||||
entry.output.append(output)
|
||||
resp = self.device.change_schedule(entry)
|
||||
return resp
|
||||
else:
|
||||
entry = self.device.get_schedule_entry(event)
|
||||
entry.output.append(output)
|
||||
|
Loading…
x
Reference in New Issue
Block a user