Skip to content
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

Merged
merged 5 commits into from
May 29, 2018
Merged

Add asyncio support for Ebox #14183

merged 5 commits into from
May 29, 2018

Conversation

titilambert
Copy link
Contributor

@titilambert titilambert commented Apr 30, 2018

Description:

Update to the latest pyebox version

Related issue (if applicable): fixes #14003

Fixes: titilambert/pyebox#6

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. 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.

@@ -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):
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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']
Copy link
Member

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):

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

Choose a reason for hiding this comment

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

'asyncio' imported but unused

@titilambert
Copy link
Contributor Author

@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)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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)
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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)
Copy link
Member

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.

@cdce8p cdce8p removed their request for review May 2, 2018 08:13
self.data = self.client.get_data()
Return True

Choose a reason for hiding this comment

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

SyntaxError: invalid syntax

@titilambert
Copy link
Contributor Author

I fixed my email, so the cla-error label can be removed

@home-assistant home-assistant deleted a comment from homeassistant May 5, 2018
@fabaff fabaff changed the title Ebox Add support for Ebox May 10, 2018
@titilambert titilambert changed the title Add support for Ebox Add asyncio support for Ebox May 26, 2018
@balloob balloob merged commit 4105429 into home-assistant:dev May 29, 2018
@balloob balloob mentioned this pull request Jun 8, 2018
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
* Fix Ebox sensor

* Fix home-assistant#14183 comments

* Update ebox.py

* Update ebox.py

* Continue fixing comments
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 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.

Please fix Home-Assistant
7 participants