Rewrite of Trafikverket weather - Multiple sensor types supported#15935
Rewrite of Trafikverket weather - Multiple sensor types supported#15935MartinHjelmare merged 11 commits intohome-assistant:devfrom endor-force:update_trafikverketsensor
Conversation
Enables users to see type of precipitation. Value returned from API is a string in swedish.
|
Moved from master to dev, tag "merging to master" can be cleared. |
Correction of tox findings
| add_devices([TrafikverketWeatherStation( | ||
| sensor_name, sensor_api, sensor_station, sensor_type)], True) | ||
|
|
||
Travis tox failed due to problem with tox build process. Correcting in a comment to trigger retry in travis..
|
|
||
| # 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. |
There was a problem hiding this comment.
line too long (110 > 79 characters)
|
|
||
| # 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" |
| <EQ name="Name" value='""" + self._station + """' /> | ||
| </FILTER> | ||
| <INCLUDE>Measurement.""" + air_vs_road + """.Temp</INCLUDE> | ||
| <INCLUDE>Measurement.""" + air_vs_road + """.""" + keytype + """</INCLUDE> |
There was a problem hiding this comment.
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.
|
Sorry, rookie here, do you know any sensor that I can look at for reference on putting protocol code in separate library? |
|
|
|
Maybe try to extend pytrafikverket: |
|
Sure, I will investigate the possibilities of using and extending pytrafikverket for this. |
Extended pytrafikverket with weather sensor collction Changed behaviour of sensor component to use pytrafikverket. Added more sensors. User need to change config to use new version. [] Documentation needs to be updated
| """Set up the Trafikverket sensor platform.""" | ||
| from pytrafikverket.trafikverket_weather import TrafikverketWeather | ||
|
|
||
| sensor_name = config.get(CONF_NAME) |
There was a problem hiding this comment.
Use dict[key] for required config keys.
|
|
||
|
|
||
| def setup_platform(hass, config, add_entities, discovery_info=None): | ||
| async def async_setup_platform(hass, config, async_add_devices, |
There was a problem hiding this comment.
Rename async_add_devices to async_add_entities.
| self._name = SENSOR_TYPES[sensor_type][0] | ||
| self._type = sensor_type | ||
| self._state = None | ||
| self._state = STATE_UNKNOWN |
| # air_vs_road contains "Air" or "Road" depending on user input. | ||
| self._state = final[air_vs_road]["Temp"] | ||
| self._weather = await\ | ||
| self._weather_api.async_get_weather(self._station) |
There was a problem hiding this comment.
Break the line after the parenthesis instead.
| self._state = None | ||
| self._state = STATE_UNKNOWN | ||
| self._unit = SENSOR_TYPES[sensor_type][1] | ||
| self._code = None |
Appreciate the feedback
|
Updated and smoke tested with some scenarios for errors. [ ] Documentation needs to be updated since it is a change in how to configure |
|
Please also add a paragraph in the PR description about the breaking change for the release notes. |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Ping me when description is updated and docs done.
|
@MartinHjelmare |
|
Please write what has changed regarding configuration. |
|
Done 👍 |
|
This is sooo great! Thanks guys! Cannot wait for the release! <3 |
Description:
Rewritten with library pytrafikverket for retreiving data.
Breaking change, requires user to update configuration!
Instead of having multiple sensor configurations per station, add only one configuration per station and select the type of measurement data to subscribe to using
monitored_conditions.The configuration value
typeshould no longer be used.Supports more weather data from Trafikverket API.
(Text values returned from API is string in Swedish (
wind_direction_textandprecipitation).)Related issue (if applicable): fixes N/A
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#6006
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc. N/AIf the code does not interact with devices: