Add support for multiple Doorbird stations#13994
Conversation
|
|
||
| return True | ||
|
|
||
| class ConfiguredDoorbird(): |
| hass_url = doorstation_config.get(CONF_CUSTOM_URL) | ||
|
|
||
| # This will make HA the only service that gets doorbell events | ||
| url = '{}{}/{}/{}'.format(hass_url, API_URL, index + 1, SENSOR_DOORBELL) |
There was a problem hiding this comment.
line too long (84 > 79 characters)
| # Get the URL of this server | ||
| hass_url = hass.config.api.base_url | ||
|
|
||
| # Override it if another is specified in the component configuration |
There was a problem hiding this comment.
line too long (80 > 79 characters)
| _LOGGER.info("Connected to DoorBird at %s as %s", device_ip, username) | ||
| doorstations.append(ConfiguredDoorbird(device, name)) | ||
| elif status[1] == 401: | ||
| _LOGGER.error("Authorization rejected by DoorBird at %s", device_ip) |
There was a problem hiding this comment.
line too long (80 > 79 characters)
| status = device.ready() | ||
|
|
||
| if status[0]: | ||
| _LOGGER.info("Connected to DoorBird at %s as %s", device_ip, username) |
There was a problem hiding this comment.
line too long (82 > 79 characters)
| device_ip = doorstation_config.get(CONF_HOST) | ||
| username = doorstation_config.get(CONF_USERNAME) | ||
| password = doorstation_config.get(CONF_PASSWORD) | ||
| name = doorstation_config.get(CONF_NAME) or 'DoorBird {}'.format(index + 1) |
There was a problem hiding this comment.
line too long (83 > 79 characters)
| import voluptuous as vol | ||
|
|
||
| from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD | ||
| from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD, \ |
There was a problem hiding this comment.
'homeassistant.const.CONF_DEVICES' imported but unused
| device.history_image_url(1, 'doorbell'), _CAMERA_LAST_VISITOR.format(doorstation.name), | ||
| _LAST_VISITOR_INTERVAL), | ||
| DoorBirdCamera( | ||
| device.history_image_url(1, 'motionsensor'), _CAMERA_LAST_MOTION.format(doorstation.name), |
There was a problem hiding this comment.
line too long (106 > 79 characters)
| async_add_devices([ | ||
| DoorBirdCamera(device.live_image_url, _CAMERA_LIVE.format(doorstation.name), _LIVE_INTERVAL), | ||
| DoorBirdCamera( | ||
| device.history_image_url(1, 'doorbell'), _CAMERA_LAST_VISITOR.format(doorstation.name), |
There was a problem hiding this comment.
line too long (103 > 79 characters)
| for doorstation in hass.data.get(DOORBIRD_DOMAIN): | ||
| device = doorstation.device | ||
| async_add_devices([ | ||
| DoorBirdCamera(device.live_image_url, _CAMERA_LIVE.format(doorstation.name), _LIVE_INTERVAL), |
There was a problem hiding this comment.
line too long (105 > 79 characters)
| username = doorstation_config.get(CONF_USERNAME) | ||
| password = doorstation_config.get(CONF_PASSWORD) | ||
| name = doorstation_config.get(CONF_NAME) \ | ||
| or 'DoorBird {}'.format(index + 1) |
There was a problem hiding this comment.
continuation line over-indented for visual indent
|
Did you see the lint errors at the travis builds? |
|
|
||
| CONFIG_SCHEMA = vol.Schema({ | ||
| DOMAIN: vol.Schema({ | ||
| vol.Required(CONF_HOST): cv.string, |
There was a problem hiding this comment.
I would like to suggest this schema:
doorbird:
gateways:
- host: <host_ip>
username: <username>
password: <password>
doorbell_events: 1
name: Side Entry
- host: <host_ip>
username: <username>
password: <password>
doorbell_events: 1
name: Front Door
In this case the schema can be extended in future with parameters applied to all gateways without another beaking change of the configuration.
cp. #13517
There was a problem hiding this comment.
This schema is better (extensible)
Although these are not really gateways I think. So gateways should be devices probably.
| CONF_DOORBELL_EVENTS = 'doorbell_events' | ||
| CONF_CUSTOM_URL = 'hass_url_override' | ||
|
|
||
| DEVICES_SCHEMA = vol.All(cv.ensure_list, |
There was a problem hiding this comment.
Call it DEVICE_SCHEMA and move the vol.All(cv.ensure_list, [DEVICE_SCHEMA]) part to the CONFIG_SCHEMA.
pvizeli
left a comment
There was a problem hiding this comment.
Why you wrap it into a devices?
doorbird:
- xy: fdsf
kds: dfsd
- ...
That allow a more clean struct if you have only one device.
|
I've suggested this schema to be future proof: #13994 (comment) |
|
@pvizeli Do you agree with the |
|
It was only a comment. With 2 devices it look okay but with only one device (and maybe the biggest case) it look a bit wired. Anyway it's only a comment :) |
|
Do you like to improve the schema of the doorbell events? You could use the entity_id instead of enumerate the devices: |
|
I think that is a good idea. I'll work on making those changes. |
Use dispatcher for doorbird pushed events.
| class ConfiguredDoorbird(): | ||
| """Attach additional information to pass along with configured device.""" | ||
|
|
||
| def __init__(self, device, name, custom_url = None): |
There was a problem hiding this comment.
unexpected spaces around keyword / parameter equals
| doorstation.device.subscribe_notification(self._event_type, url) | ||
|
|
||
|
|
||
| @asyncio.coroutine |
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Set up the Doorbird doorbell sensor platform.""" | ||
|
|
||
| doorbird = hass.data.get(DOORBIRD_DOMAIN) |
There was a problem hiding this comment.
local variable 'doorbird' is assigned to but never used
| import logging | ||
| import datetime | ||
| import voluptuous as vol | ||
| from homeassistant.core import callback |
There was a problem hiding this comment.
'homeassistant.core.callback' imported but unused
| # Get the URL of this server | ||
| hass_url = hass.config.api.base_url | ||
|
|
||
| # Override url if another is specified in the doorstation configuration |
There was a problem hiding this comment.
line too long (83 > 79 characters)
| for sensor_type in doorstation.monitored_events: | ||
| name = '{} {}'.format(doorstation.name, | ||
| SENSOR_TYPES[sensor_type][0]) | ||
| device_class = SENSOR_TYPES[sensor_type][1] |
There was a problem hiding this comment.
local variable 'device_class' is assigned to but never used
| # Get the URL of this server | ||
| hass_url = hass.config.api.base_url | ||
|
|
||
| # Override url if another is specified in the doorstation configuration |
There was a problem hiding this comment.
line too long (83 > 79 characters)
| for sensor_type in doorstation.monitored_events: | ||
| name = '{} {}'.format(doorstation.name, | ||
| SENSOR_TYPES[sensor_type][0]) | ||
| device_class = SENSOR_TYPES[sensor_type][1] |
There was a problem hiding this comment.
local variable 'device_class' is assigned to but never used
| import asyncio | ||
| import logging | ||
|
|
||
| import asyncio |
There was a problem hiding this comment.
Please sort imports 🔤 within groups standard library, 3rd party and homeassistant. There should be a blank line between the three groups.
| """Support for powering relays in a DoorBird video doorbell.""" | ||
| import datetime | ||
| import logging | ||
|
|
There was a problem hiding this comment.
Don't remove blank line between standard library and 3rd party imports.
|
|
||
| device = doorstation.device | ||
|
|
||
| switches = [] |
There was a problem hiding this comment.
Move this out of the loop. It's accessed outside the loop.
| return self._monitored_events | ||
|
|
||
|
|
||
| class DoorbirdEventSubscriber(): |
There was a problem hiding this comment.
Why is this a class? Looks like you just need a function.
|
|
||
| return True | ||
|
|
||
| def subscribe_events(hass, doorstation): |
|
@MartinHjelmare Thank you for the diligent code review. It is very helpful since I'm new to Python and HA development. Hopefully these latest changes are all that will be required. |
|
I'm fine with the state of this PR. Nevertheless I would like to point you to this comment again: #13994 (comment) It's important here/now because this is already a breaking change. The component shouldn't break again in the near future. |
|
@syssi How would I get the entity_id from within the |
|
I'm not familiar enough with HA core to know when/how an entity_id is assigned. This is ready to merge unless somebody can provide direction on @syssi's suggestion. |
|
The |
| CONF_CUSTOM_URL = 'hass_url_override' | ||
|
|
||
| DOORBELL_EVENT = 'doorbell' | ||
| MOTION_EVENT = 'motionsensor' |
There was a problem hiding this comment.
Could you call the event motion? I will approved and merge the PR afterwards.
There was a problem hiding this comment.
That is the event name required by the device API for event subscriptions.
There was a problem hiding this comment.
@oblogic7 That's only for monitor.cgi. The new schedule.cgi uses 'motion'. No need to update this PR, I'm fixing it in mine 🙂


Description:
Adds support for configuring multiple Doorbird stations.
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5205
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed: