Skip to content
Merged
Changes from all commits
Commits
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
28 changes: 22 additions & 6 deletions homeassistant/components/doorbird.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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'

Expand All @@ -37,6 +38,10 @@
'name': 'Motion',
'device_class': 'motion',
},
'relay': {
'name': 'Relay',
'device_class': 'relay',
}
}

RESET_DEVICE_FAVORITES = 'doorbird_reset_favorites'
Expand All @@ -47,6 +52,8 @@
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=[]):
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -104,7 +112,7 @@ def setup(hass, config):
return False

# Subscribe to doorbell or motion events
if events is not None:
if events:
doorstation.update_schedule(hass)

hass.data[DOMAIN] = doorstations
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -218,9 +228,8 @@ def _register_event(self, hass_url, event, schedule):

# 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:
Expand All @@ -239,6 +248,13 @@ def _register_event(self, hass_url, event, schedule):
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this return correct? It looks weird in this place. Also, nothing is checking the return value of this method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return is unnecessary, but shouldn't cause any problems since the calling code does not expect a return value. I have some other housekeeping tasks planned for this component and will clean this up as part of those changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we really return inside the loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. You're right. Guess I'll go ahead and knock out those changes...

else:
entry = self.device.get_schedule_entry(event)
entry.output.append(output)
Expand Down