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
d3493c7e
Commit
d3493c7e
authored
9 years ago
by
Daniel Høyer Iversen
Committed by
Paulus Schoutsen
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Config validation of yr sensor (#1767)
parent
24257fe4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/sensor/yr.py
+13
-7
13 additions, 7 deletions
homeassistant/components/sensor/yr.py
tests/components/sensor/test_yr.py
+13
-21
13 additions, 21 deletions
tests/components/sensor/test_yr.py
with
26 additions
and
28 deletions
homeassistant/components/sensor/yr.py
+
13
−
7
View file @
d3493c7e
...
@@ -5,9 +5,10 @@ For more details about this platform, please refer to the documentation at
...
@@ -5,9 +5,10 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.yr/
https://home-assistant.io/components/sensor.yr/
"""
"""
import
logging
import
logging
import
requests
import
requests
import
voluptuous
as
vol
import
homeassistant.helpers.config_validation
as
cv
from
homeassistant.const
import
CONF_LATITUDE
,
CONF_LONGITUDE
from
homeassistant.const
import
CONF_LATITUDE
,
CONF_LONGITUDE
from
homeassistant.helpers.entity
import
Entity
from
homeassistant.helpers.entity
import
Entity
from
homeassistant.util
import
dt
as
dt_util
from
homeassistant.util
import
dt
as
dt_util
...
@@ -18,6 +19,8 @@ _LOGGER = logging.getLogger(__name__)
...
@@ -18,6 +19,8 @@ _LOGGER = logging.getLogger(__name__)
REQUIREMENTS
=
[
'
xmltodict
'
]
REQUIREMENTS
=
[
'
xmltodict
'
]
CONF_MONITORED_CONDITIONS
=
'
monitored_conditions
'
# Sensor types are defined like so:
# Sensor types are defined like so:
SENSOR_TYPES
=
{
SENSOR_TYPES
=
{
'
symbol
'
:
[
'
Symbol
'
,
None
],
'
symbol
'
:
[
'
Symbol
'
,
None
],
...
@@ -36,6 +39,13 @@ SENSOR_TYPES = {
...
@@ -36,6 +39,13 @@ SENSOR_TYPES = {
'
dewpointTemperature
'
:
[
'
Dewpoint temperature
'
,
'
°C
'
],
'
dewpointTemperature
'
:
[
'
Dewpoint temperature
'
,
'
°C
'
],
}
}
PLATFORM_SCHEMA
=
vol
.
Schema
({
vol
.
Required
(
'
platform
'
):
'
yr
'
,
vol
.
Optional
(
CONF_MONITORED_CONDITIONS
,
default
=
[]):
[
vol
.
In
(
SENSOR_TYPES
.
keys
())],
vol
.
Optional
(
'
elevation
'
):
cv
.
positive_int
,
})
def
setup_platform
(
hass
,
config
,
add_devices
,
discovery_info
=
None
):
def
setup_platform
(
hass
,
config
,
add_devices
,
discovery_info
=
None
):
"""
Setup the Yr.no sensor.
"""
"""
Setup the Yr.no sensor.
"""
...
@@ -58,12 +68,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
...
@@ -58,12 +68,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
weather
=
YrData
(
coordinates
)
weather
=
YrData
(
coordinates
)
dev
=
[]
dev
=
[]
if
'
monitored_conditions
'
in
config
:
for
sensor_type
in
config
[
CONF_MONITORED_CONDITIONS
]:
for
variable
in
config
[
'
monitored_conditions
'
]:
dev
.
append
(
YrSensor
(
sensor_type
,
weather
))
if
variable
not
in
SENSOR_TYPES
:
_LOGGER
.
error
(
'
Sensor type:
"
%s
"
does not exist
'
,
variable
)
else
:
dev
.
append
(
YrSensor
(
variable
,
weather
))
# add symbol as default sensor
# add symbol as default sensor
if
len
(
dev
)
==
0
:
if
len
(
dev
)
==
0
:
...
...
This diff is collapsed.
Click to expand it.
tests/components/sensor/test_yr.py
+
13
−
21
View file @
d3493c7e
...
@@ -4,9 +4,8 @@ from unittest.mock import patch
...
@@ -4,9 +4,8 @@ from unittest.mock import patch
import
pytest
import
pytest
import
homeassistant.
components.sensor
as
sensor
from
homeassistant.
bootstrap
import
_setup_component
import
homeassistant.util.dt
as
dt_util
import
homeassistant.util.dt
as
dt_util
from
tests.common
import
get_test_home_assistant
from
tests.common
import
get_test_home_assistant
...
@@ -32,12 +31,9 @@ class TestSensorYr:
...
@@ -32,12 +31,9 @@ class TestSensorYr:
return_value
=
betamax_session
):
return_value
=
betamax_session
):
with
patch
(
'
homeassistant.components.sensor.yr.dt_util.utcnow
'
,
with
patch
(
'
homeassistant.components.sensor.yr.dt_util.utcnow
'
,
return_value
=
now
):
return_value
=
now
):
assert
sensor
.
setup
(
self
.
hass
,
{
assert
_setup_component
(
self
.
hass
,
'
sensor
'
,
{
'
sensor
'
:
{
'
sensor
'
:
{
'
platform
'
:
'
yr
'
,
'
platform
'
:
'
yr
'
,
'
elevation
'
:
0
}})
'
elevation
'
:
0
,
}
})
state
=
self
.
hass
.
states
.
get
(
'
sensor.yr_symbol
'
)
state
=
self
.
hass
.
states
.
get
(
'
sensor.yr_symbol
'
)
...
@@ -53,19 +49,15 @@ class TestSensorYr:
...
@@ -53,19 +49,15 @@ class TestSensorYr:
return_value
=
betamax_session
):
return_value
=
betamax_session
):
with
patch
(
'
homeassistant.components.sensor.yr.dt_util.utcnow
'
,
with
patch
(
'
homeassistant.components.sensor.yr.dt_util.utcnow
'
,
return_value
=
now
):
return_value
=
now
):
assert
sensor
.
setup
(
self
.
hass
,
{
assert
_setup_component
(
self
.
hass
,
'
sensor
'
,
{
'
sensor
'
:
{
'
sensor
'
:
{
'
platform
'
:
'
yr
'
,
'
platform
'
:
'
yr
'
,
'
elevation
'
:
0
,
'
elevation
'
:
0
,
'
monitored_conditions
'
:
[
'
monitored_conditions
'
:
{
'
pressure
'
,
'
pressure
'
,
'
windDirection
'
,
'
windDirection
'
,
'
humidity
'
,
'
humidity
'
,
'
fog
'
,
'
fog
'
,
'
windSpeed
'
]}})
'
windSpeed
'
}
}
})
state
=
self
.
hass
.
states
.
get
(
'
sensor.yr_pressure
'
)
state
=
self
.
hass
.
states
.
get
(
'
sensor.yr_pressure
'
)
assert
'
hPa
'
==
state
.
attributes
.
get
(
'
unit_of_measurement
'
)
assert
'
hPa
'
==
state
.
attributes
.
get
(
'
unit_of_measurement
'
)
...
...
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