-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
opensky sensor #7061
opensky sensor #7061
Conversation
@happyleavesaoc, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabaff and @robbiet480 to be potential reviewers. |
# pylint: disable=unused-argument | ||
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Setup the Open Sky platform.""" | ||
session = requests.Session() |
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.
Move that into OpenSkySensor.__init__
@property | ||
def unit_of_measurement(self): | ||
"""Unit of measurement.""" | ||
return UNIT_OF_MEASUREMENT |
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.
Don't use a const if you need it only on one place.
@property | ||
def icon(self): | ||
"""Icon.""" | ||
return ICON |
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.
Don't use a const if you need it only on one place.
Addressed comments. |
i gave this a test, with this config sensor:
- platform: opensky
radius: 10 # kilometers and got this error Traceback (most recent call last):
File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
result = coro.throw(exc)
File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity_component.py", line 359, in async_process_entity
new_entity, self, update_before_add=update_before_add
File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity_component.py", line 189, in async_add_entity
yield from self.hass.loop.run_in_executor(None, entity.update)
File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/brenda/.homeassistant/custom_components/sensor/opensky.py", line 109, in update
if distance > self._radius:
TypeError: unorderable types: NoneType() > float() |
@Br3nda do you have a lat/long set in your |
@happyleavesaoc yes - it is set. |
@Br3nda Ah ok, so it was an intermittent error? There's probably occasionally a flight with bad lat/long data. I added an extra check to prevent the error on the latest commit. Thanks for the feedback! |
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
SCAN_INTERVAL = timedelta(seconds=12) # opensky public limit is 10 seconds |
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 think that we should be friendly and not being too close to the limit of the API. Isn't it enough to get the data every 30 or so?
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.
Well, if you want to know when a flight enters your region, it'll be gone already in 30 seconds by the time the sensor updates.
But it is a SCAN_INTERVAL
, so people with that use case could always set it lower if we default to 30.
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.
Nice work 🐬
Description:
Report the number of flights in a given area via the OpenSky Network, and raise events for flights crossing the area boundary.
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2431
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 pass.coveragerc
.