-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
pyLoad download sensor #10089
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
pyLoad download sensor #10089
Conversation
|
||
def update(self): | ||
"""Update cached response.""" | ||
try: |
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.
trailing whitespace
|
||
@Throttle(MIN_TIME_BETWEEN_UPDATES) | ||
|
||
def update(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.
blank lines found after function decorator
return response.json() | ||
|
||
except requests.exceptions.ConnectionError as conn_exc: | ||
_LOGGER.error("Failed to update pyLoad status from %s. Error: %s", self.api_url + 'statusServer', conn_exc) |
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 (119 > 79 characters)
|
||
try: | ||
response = requests.post( | ||
self.api_url + 'statusServer', json=payload, cookies=self.login.cookies, |
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 (88 > 79 characters)
self.headers = {'content-type': CONTENT_TYPE_JSON} | ||
|
||
if username is not None and password is not None: | ||
self.payload = {'username':username, 'password':password} |
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.
missing whitespace after ':'
# Error calling the API, already logged in api.update() | ||
return | ||
|
||
if self.api.status is 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.
indentation contains mixed spaces and tabs
except requests.exceptions.ConnectionError: | ||
# Error calling the API, already logged in api.update() | ||
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.
indentation contains tabs
indentation contains mixed spaces and tabs
blank line contains whitespace
"""Return the state of the sensor.""" | ||
return self._state | ||
|
||
@property |
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.
indentation contains mixed spaces and tabs
def state(self): | ||
"""Return the state of the sensor.""" | ||
return self._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.
indentation contains tabs
indentation contains mixed spaces and tabs
blank line contains whitespace
"""Return the name of the sensor.""" | ||
return self._name | ||
|
||
@property |
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.
indentation contains mixed spaces and tabs
devices.append(new_sensor) | ||
add_devices(devices) | ||
|
||
class pyLoadSensor(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.
expected 2 blank lines, found 1
}) | ||
|
||
# pylint: disable=unused-argument | ||
def setup_platform(hass, config, 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.
expected 2 blank lines, found 1
else: | ||
self._state = value | ||
|
||
class pyLoadAPI(object): |
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.
expected 2 blank lines, found 1
"""Initialize pyLoad API and set headers needed later.""" | ||
self.api_url = api_url | ||
self.status = None | ||
self.headers = {'content-type': CONTENT_TYPE_JSON} |
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.
'content-type'
should be present in const.py
.
|
||
if username is not None and password is not None: | ||
self.payload = {'username': username, 'password': password} | ||
self.login = requests.post(api_url + 'login', data=self.payload) |
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.
All requests need a timeout.
self.api = api | ||
self._state = None | ||
self._unit_of_measurement = sensor_type[2] | ||
self.update() |
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 needed see above.
DEFAULT_NAME = 'pyLoad' | ||
DEFAULT_PORT = 8000 | ||
|
||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=5) |
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.
That's pretty fast.
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
vol.Required(CONF_HOST): cv.string, | ||
vol.Optional(CONF_MONITORED_VARIABLES, default=['speed']): | ||
vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]), |
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 is only one sensor type possible. If there are no other sensors possible with pyload then speed
should be set and configuration option be removed. If there are other you plan to integrate then it's ok.
|
||
except requests.exceptions.ConnectionError as conn_exc: | ||
_LOGGER.error("Failed to update pyLoad status from %s. Error: %s", | ||
self.api_url + 'statusServer', conn_exc) |
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.
It would only make sense to log the URL if you could use multiple instances.
"""Initialize a new pyLoad sensor.""" | ||
self._name = '{} {}'.format(client_name, sensor_type[1]) | ||
self.type = sensor_type[0] | ||
self.client_name = client_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.
This is not used.
return response.json() | ||
|
||
except requests.exceptions.ConnectionError as conn_exc: | ||
_LOGGER.error("Failed to update pyLoad status. Error: %s", conn_exc) |
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 (80 > 79 characters)
|
||
if username is not None and password is not None: | ||
self.payload = {'username': username, 'password': password} | ||
self.login = requests.post(api_url + 'login', data=self.payload, |
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.
trailing whitespace
def __init__(self, api, sensor_type, client_name): | ||
"""Initialize a new pyLoad sensor.""" | ||
self._name = '{} {}'.format(client_name, sensor_type[1]) | ||
self.type = sensor_type[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.
trailing whitespace
from homeassistant.components.sensor import PLATFORM_SCHEMA | ||
from homeassistant.const import ( | ||
CONF_HOST, CONF_PASSWORD, CONF_USERNAME, CONF_NAME, CONF_PORT, | ||
CONF_SSL, HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON, CONF_MONITORED_VARIABLES) |
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 (84 > 79 characters)
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.
Thanks 🐦
It doesn't work with https only: 2017-11-19 11:48:26 ERROR (Thread-4) [homeassistant.components.sensor.pyload] Error setting up pyLoad API: HTTPConnectionPool(host='https', port=80): Max retries exceeded with url: //my.dns.tld:8000/api/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xb11f8450>: Failed to establish a new connection: [Errno -2] Name or service not known',))
|
If there's an issue, please open an issue and link to the PR which you suspect. Don't report issues in merged PRs. Thanks! |
Description:
Support for monitoring pyLoad download speed.
Pull request in home-assistant.github.io with documentation: home-assistant/home-assistant.io#3742
Example entry for
configuration.yaml
:Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
.coveragerc
.