Update to DoorBirdPy 2.0.2#14800
Update to DoorBirdPy 2.0.2#14800Klikini wants to merge 0 commit intohome-assistant:devfrom Klikini:doorbird-v2
Conversation
|
I have tested all of the code locally except the event bus because I can't open the logbook or settings tabs in the frontend. Every tab except home is just a blank page and Chrome logs |
| device_ip = config[DOMAIN].get(CONF_HOST) | ||
| username = config[DOMAIN].get(CONF_USERNAME) | ||
| password = config[DOMAIN].get(CONF_PASSWORD) | ||
| doorbell_num = config[DOMAIN].get(CONF_DOORBELL_NUM, 1) |
There was a problem hiding this comment.
Move the default to the config schema.
|
|
||
| # Register doorbell push schedule if enabled | ||
| if config[DOMAIN].get(CONF_DOORBELL_EVENTS): | ||
| doorbell_num = config[DOMAIN].get(CONF_DOORBELL_NUM, 1) |
There was a problem hiding this comment.
This is already assigned.
| hass_url = hass.config.api.base_url | ||
|
|
||
| # Override it if another is specified in the component configuration | ||
| if config[DOMAIN].get(CONF_CUSTOM_URL): |
There was a problem hiding this comment.
Cache the config for the domain in conf, since it's accessed so frequently.
| url = '{}{}/{}'.format(hass_url, API_URL, SENSOR_DOORBELL) | ||
| device.reset_notifications() | ||
| device.subscribe_notification(SENSOR_DOORBELL, url) | ||
| # Deregister doorbell pushes if not enabled |
There was a problem hiding this comment.
Shouldn't this be done at each home assistant stop instead?
There was a problem hiding this comment.
It's deregistering the notifications that aren't in the configuration (but were on a previous start), not the ones that it registered at startup.
There was a problem hiding this comment.
Yes, but shouldn't we instead deregister everything at stop? Otherwise we need to start again to deregister.
There was a problem hiding this comment.
Where are we registering the notifications?
There was a problem hiding this comment.
When HA starts, it will register (with the DoorBird device itself) that it wants doorbell and/or motion notifications, depending on which are enabled in the HA config. It will also check to see if it there are old records (used to be in config but then got removed/commented out) for HA that it doesn't want anymore and remove them, otherwise putting a notification in your HA config is permanent even if you remove it later.
We could deregister at stop, but right now I just leave them there so they don't need to be re-registered next time HA restarts. That way there aren't any EEPROM writes on the device every time HA restarts, only when the config changes.
| if 'http' not in favs: | ||
| return False | ||
|
|
||
| for fav in list(favs['http'].values()): |
There was a problem hiding this comment.
Just iterate the dict values directly. It's not needed to make a list of the values.
for fav in favs['http'].values():|
|
||
| The favorite must exist or there will be problems. | ||
| """ | ||
| for fav_id in list(favs['http'].keys()): |
| _LOGGER.debug("Adding DoorBird switch %s", SWITCHES[switch]["name"]) | ||
| switches.append(DoorBirdSwitch(device, switch)) | ||
| relays = device.info()['RELAYS'] | ||
| relays.append("") # IR lights |
There was a problem hiding this comment.
Why not call it something readable like 'ir_light'.
There was a problem hiding this comment.
I used __ir_light__ because a device is more likely to actually be named ir_light if another one is present.
| username = config[DOMAIN].get(CONF_USERNAME) | ||
| password = config[DOMAIN].get(CONF_PASSWORD) | ||
| from doorbirdpy import DoorBird, DoorBirdScheduleEntrySchedule | ||
|
|
|
I think their changes are more involved, so their PR should be merged first and then I will manually reapply my changes in a new PR to the new code handling each device. |
|
I deliberately did not make any updates to API calls as part of my PR. All of my devices are up-to-date on firmware and I did verify that the notification endpoint is still available. The documentation states that notifications are automatically converted to the new schedule format so the existing approach still works well. The API calls should be updated in case the notifications endpoint is deprecated in a future release. |
|
@oblogic7 Yes, which is why your PR should merge first. I can reapply my changes to your new code easily once it merges because most of my changes were in the DoorBirdPy library itself. |
|
Please rebase and re-apply your changes! :-) |
|
Moved to #14933 |
Description:
Update to DoorBirdBy 2.0.2, which uses the new version (0.21) of the DoorBird LAN API.
Pull request in home-assistant.github.io with documentation: home-assistant/home-assistant.io#5487
Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py.