Skip to content

Update to DoorBirdPy 2.0.2#14800

Closed
Klikini wants to merge 0 commit intohome-assistant:devfrom
Klikini:doorbird-v2
Closed

Update to DoorBirdPy 2.0.2#14800
Klikini wants to merge 0 commit intohome-assistant:devfrom
Klikini:doorbird-v2

Conversation

@Klikini
Copy link
Copy Markdown
Contributor

@Klikini Klikini commented Jun 3, 2018

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:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.

@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented Jun 3, 2018

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 GET http://127.0.0.1:8123/undefined 404 (Not Found) to the console. Is this a known issue with the dev branch or did I screw something up with my test instance?

Comment thread homeassistant/components/doorbird.py Outdated
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)
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.

Move the default to the config schema.

Comment thread homeassistant/components/doorbird.py Outdated

# Register doorbell push schedule if enabled
if config[DOMAIN].get(CONF_DOORBELL_EVENTS):
doorbell_num = config[DOMAIN].get(CONF_DOORBELL_NUM, 1)
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.

This is already assigned.

Comment thread homeassistant/components/doorbird.py Outdated
hass_url = hass.config.api.base_url

# Override it if another is specified in the component configuration
if config[DOMAIN].get(CONF_CUSTOM_URL):
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.

Cache the config for the domain in conf, since it's accessed so frequently.

Comment thread homeassistant/components/doorbird.py Outdated
url = '{}{}/{}'.format(hass_url, API_URL, SENSOR_DOORBELL)
device.reset_notifications()
device.subscribe_notification(SENSOR_DOORBELL, url)
# Deregister doorbell pushes if not enabled
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.

Shouldn't this be done at each home assistant stop instead?

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.

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.

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.

Yes, but shouldn't we instead deregister everything at stop? Otherwise we need to start again to deregister.

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.

Where are we registering the notifications?

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.

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.

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.

Sounds good!

Comment thread homeassistant/components/doorbird.py Outdated
if 'http' not in favs:
return False

for fav in list(favs['http'].values()):
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Jun 5, 2018

Choose a reason for hiding this comment

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

Just iterate the dict values directly. It's not needed to make a list of the values.

for fav in favs['http'].values():

Comment thread homeassistant/components/doorbird.py Outdated

The favorite must exist or there will be problems.
"""
for fav_id in list(favs['http'].keys()):
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.

for fav in favs['http']:

_LOGGER.debug("Adding DoorBird switch %s", SWITCHES[switch]["name"])
switches.append(DoorBirdSwitch(device, switch))
relays = device.info()['RELAYS']
relays.append("") # IR lights
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.

Why not call it something readable like 'ir_light'.

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.

I used __ir_light__ because a device is more likely to actually be named ir_light if another one is present.

Comment thread homeassistant/components/doorbird.py Outdated
username = config[DOMAIN].get(CONF_USERNAME)
password = config[DOMAIN].get(CONF_PASSWORD)
from doorbirdpy import DoorBird, DoorBirdScheduleEntrySchedule

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blank line contains whitespace

@syssi
Copy link
Copy Markdown
Member

syssi commented Jun 9, 2018

@Klikini Thanks for your contribution! Are you aware of #13994? Could you support @oblogic7? No matter which PR gets merged first one of you has to port the changes unfortunately. :-(

@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented Jun 9, 2018

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.

@oblogic7
Copy link
Copy Markdown
Contributor

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.

@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented Jun 10, 2018

@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.

@syssi
Copy link
Copy Markdown
Member

syssi commented Jun 10, 2018

Please rebase and re-apply your changes! :-)

@Klikini
Copy link
Copy Markdown
Contributor Author

Klikini commented Jun 11, 2018

Moved to #14933

@home-assistant home-assistant locked and limited conversation to collaborators Dec 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants