-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
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
Use luftdaten module #10970
Use luftdaten module #10970
Conversation
from luftdaten import Luftdaten | ||
|
||
self.hass = hass | ||
self._websession = async_get_clientsession(self.hass) |
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.
hass.helpers.aiohttp_client.async_get_clientsession()
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 line 16.
try: | ||
yield from self.data.async_get_data() | ||
except LuftdatenError: | ||
_LOGGER.error("Unable to retrieve data from luftdaten.info") | ||
self.data = 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.
Shouldn't it be able to retry at next 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.
Yeah, would make sense.
|
||
rest_client = LuftdatenData(resource, verify_ssl) | ||
rest_client.update() | ||
yield from luftdaten.async_get() |
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 method in the data class by that 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.
My mistake, see below.
@property | ||
def device_state_attributes(self): | ||
"""Return the state attributes.""" | ||
if self.luftdaten 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.
This can't happen.
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.
True.
def async_update(self): | ||
"""Get the latest data from luftdaten.info and update the state.""" | ||
try: | ||
yield from self.luftdaten.async_get() |
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.
Wrong method call.
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.
What would the correct call be?
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.
Sorry I missed that you had changed the name, and I assumed the data class also would have a method called update
or async_update
since that is what we usually use.
Nevermind this comment. 😊
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 will rename it to be consistent with the other platforms.
"""Get the latest data from luftdaten.info and update the state.""" | ||
try: | ||
yield from self.luftdaten.async_update() | ||
except TypeError: |
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.
When could this error happen?
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 sensors are under the control of their owner and if one decided to changing something it can happen that several update windows of the Luftdate API are missed. There are sensors which are not properly implemented and only send partial data. Also, there is no way to tell if the sensor is temporary offline or permanent.
This can be removed if the Luftdaten API is declared stable and the module implements more error handling.
return self._state | ||
try: | ||
return self.luftdaten.data.values[self.sensor_type] | ||
except AttributeError: |
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.
When could this error happen?
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.
Seems to be obsolete with the latest 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.
Looks good!
Breaking change: |
…into dev * 'dev' of https://github.com/home-assistant/home-assistant: Report availability for TP-Link smart bulbs (home-assistant#10976) Bump pyatv to 0.3.9 (home-assistant#11104) Use luftdaten module (home-assistant#10970) Bump pymusiccast to version 0.1.6 (home-assistant#11091) Update tellcore-net to 0.4 (home-assistant#11087) Upgrade shodan to 1.7.7 (home-assistant#11084) Upgrade youtube_dl to 2017.12.10 (home-assistant#11080) Upgrade psutil to 5.4.2 (home-assistant#11083) Upgrade yarl to 0.16.0 (home-assistant#11078) Upgrade aiohttp to 2.3.6 (home-assistant#11079) Allow tradfri to read the available state of the device (home-assistant#11056)
Description:
Related issue (if applicable): fixes #10951
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4195
Example entry for
configuration.yaml
(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable ([example][ex-requir]).requirements_all.txt
by runningscript/gen_requirements_all.py
.