Skip to content

DoorBird Component#9281

Merged
MartinHjelmare merged 7 commits into
home-assistant:devfrom
Klikini:doorbird-2
Sep 17, 2017
Merged

DoorBird Component#9281
MartinHjelmare merged 7 commits into
home-assistant:devfrom
Klikini:doorbird-2

Conversation

@Klikini
Copy link
Copy Markdown
Contributor

@Klikini Klikini commented Sep 3, 2017

Description:

Adds components for the DoorBird video doorbell.

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#3147

Example entry for configuration.yaml (if applicable):

doorbird:
  host: 192.168.2.16
  username: ghaigb0001
  password: **********

binary_sensor:
  - platform: doorbird
    monitored_conditions:
      - doorbell

camera:
  - platform: doorbird
    last_visitor: true

switch:
  - platform: doorbird
    switches:
      - light_on
      - open_door

Checklist:

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

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

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

"""Wait for the correct amount of assumed time to pass."""
if self._state and self._assume_off <= datetime.datetime.now():
self._state = False
self._assume_off = datetime.datetime.min No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no newline at end of file

Comment thread homeassistant/components/doorbird.py Outdated
else:
_LOGGER.error("Could not connect to DoorBird at %s: Error %s",
ip, str(status[1]))
return False No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no newline at end of file


def disable_motion_detection(self):
"""Network callbacks are not supported by HA yet."""
pass No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no newline at end of file

@Throttle(_MIN_UPDATE_INTERVAL)
def update(self):
"""Pull the latest value from the device."""
self._state = self._device.doorbell_state() No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no newline at end of file

@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented Sep 5, 2017

Fix lint please...

"""Initialize a binary sensor on a DoorBird device."""
self._device = device
self._sensor_type = sensor_type
self._state = STATE_UNKNOWN
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.

Init state as None.

class DoorBirdCamera(Camera):
"""The camera on a DoorBird device."""

def __init__(self, hass, url, name, interval=None):
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.

Don't pass in hass. It will be set on the entity when it has been added to home assistant.

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.

What do I replace the references with to access that? self.hass?

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!


add_devices(switches)
_LOGGER.info("Added DoorBird switches")
return True
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.

Platforms for EntityComponent should not return anything.

"""A relay in a DoorBird device."""
def __init__(self, device, switch):
"""Initialize a relay in a DoorBird device."""
if switch not in SWITCHES:
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.

You already validate this in the config schema.


now = datetime.datetime.now()
self._assume_off = now + SWITCHES[self._switch]["time"]
return True
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.

Remove.


def turn_off(self, **kwargs):
"""The relays are time-based and cannot be turned off."""
return False
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.

Raise not implemented error.

"icon": {
True: "bell-ring",
False: "bell",
"None": "bell-outline"
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 map this to None?

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 assumed None behaved like null and would cause problems. I guess not!

"""Get the name of the camera."""
return self._name

def camera_image(self):
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.

Remove this. Since you implement the async version you don't need the sync version.


def enable_motion_detection(self):
"""Network callbacks are not supported by HA yet."""
pass
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.

Don't overwrite if you don't support it.


def disable_motion_detection(self):
"""Network callbacks are not supported by HA yet."""
pass
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.

Don't overwrite if you don't support it.

import async_timeout

from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
from homeassistant.components.doorbird import DOMAIN
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.

Fix. See above.

switches = []
for switch in SWITCHES:
if switch in config.get(CONF_SWITCHES):
_LOGGER.debug("Adding DoorBird switch " +
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.

_LOGGER.debug("Adding DoorBird switch %s", SWITCHES[switch]["name"])

_LIVE_INTERVAL)]

if config.get(CONF_SHOW_LAST_VISITOR):
_LOGGER.debug("Adding DoorBird camera " + _CAMERA_LAST_VISITOR)
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.

_LOGGER.debug("Adding DoorBird camera %s", _CAMERA_LAST_VISITOR)

"""Set up the DoorBird camera platform."""
device = hass.data.get(DOMAIN)

_LOGGER.debug("Adding DoorBird camera " + _CAMERA_LIVE)
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.

_LOGGER.debug("Adding DoorBird camera %s", _CAMERA_LIVE)

self._device = device
self._sensor_type = sensor_type
self._state = None
super(DoorBirdBinarySensor, self).__init__()
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.

Remove. There's no init methods in the parent classes.


async_add_devices(entities)
_LOGGER.info("Added DoorBird camera(s)")
return True
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.

Remove.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'homeassistant.util.async.run_coroutine_threadsafe' imported but unused

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

One fix and this should be good to go.

"""Set up the DoorBird binary sensor component."""
device = hass.data.get(DOORBIRD_DOMAIN)
add_devices([DoorBirdBinarySensor(device, "doorbell")], True)
return True
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.

Remove. Sorry I missed it before.

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Nice!

@MartinHjelmare MartinHjelmare merged commit 5f24cc2 into home-assistant:dev Sep 17, 2017
@balloob balloob mentioned this pull request Sep 22, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Mar 3, 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