Refactored Arlo component and enhanced Arlo API queries and times#14823
Refactored Arlo component and enhanced Arlo API queries and times#14823MartinHjelmare merged 17 commits intohome-assistant:devfrom
Conversation
|
|
||
| def __init__(self, hub): | ||
| """Initialize the entity.""" | ||
| self.hub = hub |
There was a problem hiding this comment.
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.
Decorate this with @callback imported from core.py.
| """Return icon.""" | ||
| return ICON | ||
|
|
||
| @asyncio.coroutine |
There was a problem hiding this comment.
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.
Use self.async_schedule_update_ha_state.
| return | ||
| i += 1 | ||
| self._state = None | ||
| _LOGGER.info("Updating Arlo Alarm Control Panel %s", self.name) |
| # 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.
This is better:
arlo_base_station = next((
station for station in arlo.base_stations), None)
if arlo_base_station is None:
return False| 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.
Why would there be an attribute error?
The index error is solved by using my suggestion above.
There was a problem hiding this comment.
Yes, that is not needed anymore. Good refactoring!! Thanks
| """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.
Don't change to dict.get. We know that the key will be in the dict.
| def should_poll(self): | ||
| """Camera should poll periodically.""" | ||
| return True | ||
| return False |
There was a problem hiding this comment.
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.
Pass True as argument to call the update method before updating state.
self.async_schedule_update_ha_state(True)| """Set up an Arlo IP Camera.""" | ||
| arlo = hass.data.get(DATA_ARLO).hub | ||
| arlo = hass.data[DATA_ARLO] | ||
| if not arlo: |
| """Set up an Arlo IP sensor.""" | ||
| arlo = hass.data.get(DATA_ARLO).hub | ||
| arlo = hass.data.get(DATA_ARLO) | ||
| if not arlo: |
| """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.
continuation line over-indented for visual indent
| @callback | ||
| def _update_callback(self): | ||
| """Call update method.""" | ||
| self.async_schedule_update_ha_state() |
| return self._camera.last_image | ||
| return self._camera.last_image_from_cache | ||
|
|
||
| @asyncio.coroutine |
There was a problem hiding this comment.
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.
Update this like my previous comment. I haven't commented on all the places that needs the same changes.
|
|
||
| def _update_callback(self): | ||
| """Call update method.""" | ||
| self.schedule_update_ha_state(True) |
|
@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! |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Some small fixes left. You can also remove the second argument True in the camera platform call to add_devices.
| arlo = hass.data.get(DATA_ARLO) | ||
| arlo = hass.data[DATA_ARLO] | ||
| if not arlo: | ||
| return False |
| @callback | ||
| def _update_callback(self): | ||
| """Call update method.""" | ||
| self.async_schedule_update_ha_state(True) |
There was a problem hiding this comment.
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 |
| """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.
I don't think this can happen?
|
Thanks @MartinHjelmare PR updated. 👍 |
|
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:
REQUIREMENTSvariable ([example][ex-requir]).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: