Skip to content
19 changes: 13 additions & 6 deletions homeassistant/components/sensor/trafikverket_weatherstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
vol.Required(CONF_NAME): cv.string,
vol.Required(CONF_API_KEY): cv.string,
vol.Required(CONF_STATION): cv.string,
vol.Required(CONF_TYPE): vol.In(['air', 'road']),
vol.Required(CONF_TYPE): vol.In(['air', 'road', 'precipitation']),
})


Expand Down Expand Up @@ -73,8 +73,9 @@ def state(self):

@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
"""Return the unit of measurement for temperature sensors."""
if (self._type == 'road') or (self._type == 'air'):
return TEMP_CELSIUS

@property
def device_state_attributes(self):
Expand All @@ -88,8 +89,13 @@ def update(self):

if self._type == 'road':
air_vs_road = 'Road'
keytype = 'Temp'
elif self._type == 'precipitation':
air_vs_road = 'Precipitation'
keytype = 'Type'
else:
air_vs_road = 'Air'
keytype = 'Temp'

xml = """
<REQUEST>
Expand All @@ -98,7 +104,7 @@ def update(self):
<FILTER>
<EQ name="Name" value='""" + self._station + """' />
</FILTER>
<INCLUDE>Measurement.""" + air_vs_road + """.Temp</INCLUDE>
<INCLUDE>Measurement.""" + air_vs_road + """.""" + keytype + """</INCLUDE>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot accept any PR for this platform until all protocol specific code has been extracted into a third party lib which is then used.

</QUERY>
</REQUEST>"""

Expand All @@ -118,5 +124,6 @@ def update(self):
_LOGGER.error("Incorrect weather station or API key")
return

# air_vs_road contains "Air" or "Road" depending on user input.
self._state = final[air_vs_road]["Temp"]
# air_vs_road contains "Air", "Road" or "Precipitation"
# depending on user input as well as suffix key.
self._state = final[air_vs_road][keytype]