-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Refactored Arlo component and enhanced Arlo API queries and times #14823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
homeassistant/components/arlo.py
Outdated
|
||
def __init__(self, hub): | ||
"""Initialize the entity.""" | ||
self.hub = hub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why store the hub on another instance if it's just that attribute and no methods needed?
async_dispatcher_connect( | ||
self.hass, SIGNAL_UPDATE_ARLO, self._update_callback) | ||
|
||
def _update_callback(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decorate this with @callback
imported from core.py.
@@ -68,24 +69,29 @@ def icon(self): | |||
"""Return icon.""" | |||
return ICON | |||
|
|||
@asyncio.coroutine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're now using Python 3.5 async syntax, ie async def
.
|
||
def _update_callback(self): | ||
"""Call update method.""" | ||
self.schedule_update_ha_state(True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use self.async_schedule_update_ha_state
.
return | ||
i += 1 | ||
self._state = None | ||
_LOGGER.info("Updating Arlo Alarm Control Panel %s", self.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Max debug.
homeassistant/components/arlo.py
Outdated
# assign refresh period to base station thread | ||
try: | ||
if arlo.base_stations: | ||
arlo_base_station = arlo.base_stations[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better:
arlo_base_station = next((
station for station in arlo.base_stations), None)
if arlo_base_station is None:
return False
homeassistant/components/arlo.py
Outdated
if arlo.base_stations: | ||
arlo_base_station = arlo.base_stations[0] | ||
arlo_base_station.refresh_rate = scan_interval.total_seconds() | ||
except (AttributeError, IndexError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would there be an attribute error?
The index error is solved by using my suggestion above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is not needed anymore. Good refactoring!! Thanks
@@ -145,7 +154,7 @@ def motion_detection_enabled(self): | |||
def set_base_station_mode(self, mode): | |||
"""Set the mode in the base station.""" | |||
# Get the list of base stations identified by library | |||
base_stations = self.hass.data[DATA_ARLO].base_stations | |||
base_stations = self.hass.data.get(DATA_ARLO).hub.base_stations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't change to dict.get
. We know that the key will be in the dict.
@@ -135,7 +144,7 @@ def brand(self): | |||
@property | |||
def should_poll(self): | |||
"""Camera should poll periodically.""" | |||
return True | |||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the default for cameras.
Thanks for the review @MartinHjelmare Good tips indeed!! Please let me know what you think now. I hope to update the documentation tonight so then we can get this merged. |
def _update_callback(self): | ||
"""Call update method.""" | ||
self.schedule_update_ha_state(True) | ||
self.async_schedule_update_ha_state() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass True
as argument to call the update
method before updating state.
self.async_schedule_update_ha_state(True)
@@ -49,7 +49,7 @@ | |||
|
|||
def setup_platform(hass, config, add_devices, discovery_info=None): | |||
"""Set up an Arlo IP Camera.""" | |||
arlo = hass.data.get(DATA_ARLO).hub | |||
arlo = hass.data[DATA_ARLO] | |||
if not arlo: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't happen.
@@ -39,7 +39,7 @@ | |||
|
|||
def setup_platform(hass, config, add_devices, discovery_info=None): | |||
"""Set up an Arlo IP sensor.""" | |||
arlo = hass.data.get(DATA_ARLO).hub | |||
arlo = hass.data.get(DATA_ARLO) | |||
if not arlo: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
homeassistant/components/arlo.py
Outdated
"""Call ArloHub to refresh information.""" | ||
_LOGGER.info("Updating Arlo Hub component") | ||
hass.data[DATA_ARLO].update(update_cameras=True, | ||
update_base_station=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line over-indented for visual indent
@callback | ||
def _update_callback(self): | ||
"""Call update method.""" | ||
self.async_schedule_update_ha_state() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add True
as argument.
return self._camera.last_image | ||
return self._camera.last_image_from_cache | ||
|
||
@asyncio.coroutine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update all coroutines to use new syntax.
async_dispatcher_connect( | ||
self.hass, SIGNAL_UPDATE_ARLO, self._update_callback) | ||
|
||
def _update_callback(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this like my previous comment. I haven't commented on all the places that needs the same changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my bad.
|
||
def _update_callback(self): | ||
"""Call update method.""" | ||
self.schedule_update_ha_state(True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
@MartinHjelmare thanks again for the code review. I've updated the documentation and code. 🏆 |
Seeing a lot of errors (started appearing after about 14 minutes of restarting) with the latest code https://hastebin.com/evogidegih.sql |
@arsaboo I got the same here. Thanks for the heads up. I'm working on this now |
@arsaboo it seems we got it now. Please let me know if works for you 👍 |
Looks like everything (except the For some reason, |
@arsaboo thanks for your update. I'm glad this worked and fixed the huge amount of calls made to the Arlo API. @MartinHjelmare does that sound a good plan? Could we get this merged so then our users can get to use Thanks to everyone who helped on this! 👍 |
I will let @MartinHjelmare decide, but given that Arlo is currently broken, it will be great if we can get this merged soon. Thanks @tchellomello for all your efforts. |
Sounds good! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small fixes left. You can also remove the second argument True
in the camera platform call to add_devices
.
}) | ||
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Set up an Arlo IP Camera.""" | ||
arlo = hass.data.get(DATA_ARLO) | ||
arlo = hass.data[DATA_ARLO] | ||
if not arlo: | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only return
.
@callback | ||
def _update_callback(self): | ||
"""Call update method.""" | ||
self.async_schedule_update_ha_state(True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no update
method for this entity anymore so we don't need the argument True
here. Sorry if I said so earlier.
|
||
async_add_devices(sensors, True) | ||
add_devices(sensors, True) | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this.
}) | ||
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Set up an Arlo IP Camera.""" | ||
arlo = hass.data.get(DATA_ARLO) | ||
arlo = hass.data[DATA_ARLO] | ||
if not arlo: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this can happen?
Thanks @MartinHjelmare PR updated. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Hi Guys, fantastic work on this, I love that it has my Arlo cameras integrated and I can use automations to control them using presence detection but has the alarm_control_panel issue been addressed? I still see unknown after a while and it then stays there? Cheers |
Description:
Arlo does not offer an official API so all this work is based on reverse engineering.
Refactored Arlo component and enhanced Arlo API queries and times.
This PR also added a service call method to force the entities to be updated.
Related issue (if applicable): fixes #13176
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5508
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:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTS
variable ([example][ex-requir]).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices: