-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
Add asyncio support for Ebox #14183
Add asyncio support for Ebox #14183
Conversation
@@ -62,25 +62,23 @@ | |||
}) | |||
|
|||
|
|||
def setup_platform(hass, config, add_devices, discovery_info=None): | |||
@asyncio.coroutine | |||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): |
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.
Below, you use the new async
/await
syntax and here the @asyncio.coroutine
decorator. Please convert this method to async def async_setup_platform
and replace yield from
with await
in the new method.
|
||
name = config.get(CONF_NAME) | ||
|
||
sensors = [] | ||
for variable in config[CONF_MONITORED_VARIABLES]: | ||
_LOGGER.error("EBOX %s", variable) |
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 not an error log statement.
sensors.append(EBoxSensor(ebox_data, variable, name)) | ||
|
||
add_devices(sensors, True) | ||
async_add_devices(sensors, 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.
Why did you replace True
with False
here. Do you not want the sensors to automatically fill their value on startup?
except PyEboxError as exp: | ||
_LOGGER.error("Error on receive last EBox data: %s", exp) | ||
return | ||
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.
Nothin is checking the return value. Please just write return
(also below)
|
||
# pylint: disable=import-error | ||
REQUIREMENTS = [] # ['pyebox==0.1.0'] - disabled because it breaks pip10 | ||
REQUIREMENTS = ['pyebox==1.1.2'] |
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.
Looking at the source for pyebox, I think timeouts are not done correctly. You're passing a timeout
parameter to the .get
and .post
requests but that is not the overall timeout for the request. See this page for an example of timeouts in aiohttp: https://aiohttp.readthedocs.io/en/stable/
@@ -62,25 +62,21 @@ | |||
}) | |||
|
|||
|
|||
def setup_platform(hass, config, add_devices, discovery_info=None): | |||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): |
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.
line too long (85 > 79 characters)
@@ -6,10 +6,10 @@ | |||
For more details about this platform, please refer to the documentation at | |||
https://home-assistant.io/components/sensor.ebox/ | |||
""" | |||
import asyncio |
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.
'asyncio' imported but unused
@OttoWinter Thanks for your review ! I fixed everything included timeout in the pyebox library (new release 1.1.3) |
@@ -32,7 +31,7 @@ | |||
DEFAULT_NAME = 'EBox' | |||
|
|||
REQUESTS_TIMEOUT = 15 | |||
SCAN_INTERVAL = timedelta(minutes=5) | |||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15) |
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 change this from SCAN_INTERVAL? With SCAN_INTERVAL, Home Assistant will make sure to not call update more than once every 15 minutes per entity.
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.
Setting both constants and a throttle is good if you want to have a hard limit on the interval and set a default interval for updates. Users can override SCAN_INTERVAL
but not the throttle.
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.
@balloob that is a data object, so it need a throttle
_LOGGER.error("Failed login: %s", error) | ||
return False | ||
httpsession = hass.helpers.aiohttp_client.async_get_clientsession() | ||
ebox_data = EBoxData(username, password, httpsession) |
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.
Are you no longer validating that the user/pass are correct?
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 wanted to speed up the startup. If user/password are not correct, we will get an error in the logs at the next check and all sensors will be empty.
Also, Ebox website are often in maintenance, so if you restart your hass daemon when the website is unavailable, the component is disabled and you have to restart hass later.
Are you correct with this, or do you prefer to keep the user/password check ?
Thanks
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.
Keep the user/pass check, raise PlatformNotReady
if it's not ready yet.
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.
Fixed
self.data = self.client.get_data() | ||
return |
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.
Not necessary return.
@@ -32,7 +31,7 @@ | |||
DEFAULT_NAME = 'EBox' | |||
|
|||
REQUESTS_TIMEOUT = 15 | |||
SCAN_INTERVAL = timedelta(minutes=5) | |||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15) |
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.
Setting both constants and a throttle is good if you want to have a hard limit on the interval and set a default interval for updates. Users can override SCAN_INTERVAL
but not the throttle.
self.data = self.client.get_data() | ||
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.
SyntaxError: invalid syntax
I fixed my email, so the cla-error label can be removed |
* Fix Ebox sensor * Fix home-assistant#14183 comments * Update ebox.py * Update ebox.py * Continue fixing comments
Description:
Update to the latest pyebox version
Related issue (if applicable): fixes #14003
Fixes: titilambert/pyebox#6
Checklist:
tox
. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.