Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
e2465da7
Commit
e2465da7
authored
6 years ago
by
Daniel Høyer Iversen
Committed by
Martin Hjelmare
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
yr: use async syntax (#16563)
parent
6bd120ff
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/sensor/yr.py
+9
-12
9 additions, 12 deletions
homeassistant/components/sensor/yr.py
with
9 additions
and
12 deletions
homeassistant/components/sensor/yr.py
+
9
−
12
View file @
e2465da7
...
...
@@ -66,9 +66,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
@asyncio.coroutine
def
async_setup_platform
(
hass
,
config
,
async_add_entities
,
discovery_info
=
None
):
async
def
async_setup_platform
(
hass
,
config
,
async_add_entities
,
discovery_info
=
None
):
"""
Set up the Yr.no sensor.
"""
elevation
=
config
.
get
(
CONF_ELEVATION
,
hass
.
config
.
elevation
or
0
)
forecast
=
config
.
get
(
CONF_FORECAST
)
...
...
@@ -93,7 +92,7 @@ def async_setup_platform(hass, config, async_add_entities,
weather
=
YrData
(
hass
,
coordinates
,
forecast
,
dev
)
async_track_utc_time_change
(
hass
,
weather
.
updating_devices
,
minute
=
31
)
yield
from
weather
.
fetching_data
()
await
weather
.
fetching_data
()
class
YrSensor
(
Entity
):
...
...
@@ -156,8 +155,7 @@ class YrData:
self
.
data
=
{}
self
.
hass
=
hass
@asyncio.coroutine
def
fetching_data
(
self
,
*
_
):
async
def
fetching_data
(
self
,
*
_
):
"""
Get the latest data from yr.no.
"""
import
xmltodict
...
...
@@ -169,12 +167,12 @@ class YrData:
try
:
websession
=
async_get_clientsession
(
self
.
hass
)
with
async_timeout
.
timeout
(
10
,
loop
=
self
.
hass
.
loop
):
resp
=
yield
from
websession
.
get
(
resp
=
await
websession
.
get
(
self
.
_url
,
params
=
self
.
_urlparams
)
if
resp
.
status
!=
200
:
try_again
(
'
{} returned {}
'
.
format
(
resp
.
url
,
resp
.
status
))
return
text
=
yield
from
resp
.
text
()
text
=
await
resp
.
text
()
except
(
asyncio
.
TimeoutError
,
aiohttp
.
ClientError
)
as
err
:
try_again
(
err
)
...
...
@@ -186,11 +184,10 @@ class YrData:
try_again
(
err
)
return
yield
from
self
.
updating_devices
()
await
self
.
updating_devices
()
async_call_later
(
self
.
hass
,
60
*
60
,
self
.
fetching_data
)
@asyncio.coroutine
def
updating_devices
(
self
,
*
_
):
async
def
updating_devices
(
self
,
*
_
):
"""
Find the current data from self.data.
"""
if
not
self
.
data
:
return
...
...
@@ -256,4 +253,4 @@ class YrData:
tasks
.
append
(
dev
.
async_update_ha_state
())
if
tasks
:
yield
from
asyncio
.
wait
(
tasks
,
loop
=
self
.
hass
.
loop
)
await
asyncio
.
wait
(
tasks
,
loop
=
self
.
hass
.
loop
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment