From b3580f46b955934659757a8330ba000d98f9a979 Mon Sep 17 00:00:00 2001 From: Matt Snyder Date: Fri, 11 Jan 2019 22:45:03 -0600 Subject: [PATCH] Update doorbird events to include URLs on event_data (#19262) * Update doorbird events to include URLs on event_data as shown in documentation. (cherry picked from commit 2405bc96fe1b3a93ea8466e48db6b7df8df02235) * Format timestamp * Update timestamp * Lint --- homeassistant/components/doorbird.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/doorbird.py b/homeassistant/components/doorbird.py index a3aab7e8dd9..f952d1ddc1c 100644 --- a/homeassistant/components/doorbird.py +++ b/homeassistant/components/doorbird.py @@ -12,7 +12,7 @@ from homeassistant.components.http import HomeAssistantView from homeassistant.const import CONF_HOST, CONF_USERNAME, \ CONF_PASSWORD, CONF_NAME, CONF_DEVICES, CONF_MONITORED_CONDITIONS import homeassistant.helpers.config_validation as cv -from homeassistant.util import slugify +from homeassistant.util import slugify, dt as dt_util REQUIREMENTS = ['doorbirdpy==2.0.4'] @@ -319,6 +319,16 @@ class ConfiguredDoorBird(): return None + def get_event_data(self): + """Get data to pass along with HA event.""" + return { + 'timestamp': dt_util.utcnow().isoformat(), + 'live_video_url': self._device.live_video_url, + 'live_image_url': self._device.live_image_url, + 'rtsp_live_video_url': self._device.rtsp_live_video_url, + 'html5_viewer_url': self._device.html5_viewer_url + } + class DoorBirdRequestView(HomeAssistantView): """Provide a page for the device to call.""" @@ -346,7 +356,14 @@ class DoorBirdRequestView(HomeAssistantView): if request_token == '' or not authenticated: return web.Response(status=401, text='Unauthorized') - hass.bus.async_fire('{}_{}'.format(DOMAIN, sensor)) + doorstation = get_doorstation_by_slug(hass, sensor) + + if doorstation: + event_data = doorstation.get_event_data() + else: + event_data = {} + + hass.bus.async_fire('{}_{}'.format(DOMAIN, sensor), event_data) return web.Response(status=200, text='OK')