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
Added Met Office weather and sensor components #6742
Conversation
Hi @jacobtomlinson, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
""" | ||
|
||
import logging | ||
import datetime |
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.
'datetime' imported but unused
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.
Resolved
This has been raised to replace #5463. However it's not 100% finished and is still undergoing some testing. |
e9275f8
to
ae6996f
Compare
ae6996f
to
940f57d
Compare
Good to go at my end |
REQUIREMENTS = ['datapoint==0.4.3'] | ||
|
||
CONF_ATTRIBUTION = "Data provided by the Met Office" | ||
CONF_MO_API_KEY = 'api_key' |
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.
We have CONF_API_KEY
in const.py
. i don't see a good reason to introduce CONF_MO_API_KEY
.
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.
Fixed.
'weather': ['Weather', None], | ||
'temperature': ['Temperature', TEMP_CELSIUS], | ||
'feels_like_temperature': ['Feels Like Temperature', TEMP_CELSIUS], | ||
'wind_speed': ['Wind Speed', 'mps'], |
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.
Other platforms are using m/s
.
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.
Done
@property | ||
def name(self): | ||
"""Return the name of the sensor.""" | ||
return 'Met Office {}'.format(SENSOR_TYPES[self._condition][0]) |
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.
Often DEFAULT_NAME
is used if the user is not giving a name.
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.
This is in keeping with the bom component. Also your comment here is at odds with your comment on the weather component about using CONF_NAME
.
Do you suggest using CONF_NAME
if it has been set and DEFAULT_NAME
otherwise?
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.
This is useful for users who are enabling multiple platform.
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.
Ok I'll get that done.
Support for UK Met Office weather service. | ||
|
||
For more details about this platform, please refer to the documentation at | ||
https://home-assistant.io/components/sensor.metoffice/ |
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.
Link needs to match the component otherwise the error message of the configuration check points to the wrong location. sensor.*
-> weather.*
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.
done
datapoint = dp.connection(api_key=config.get(CONF_MO_API_KEY)) | ||
|
||
if None in (hass.config.latitude, hass.config.longitude): | ||
_LOGGER.error("Latitude or longitude not set in Home Assistant config") |
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.
To make this platform more generic, I would like to suggest that the user can specify the location in the configuration and use the data from a different location.
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.
Agreed. Will add this.
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.
Done. User's can specify latitude
and longitude
in the component configs, and if they do not it will default to their home latitude
and longitude
.
Documentation also updated in home-assistant/home-assistant.io#2318.
@property | ||
def condition(self): | ||
"""Return the current condition.""" | ||
return self.data.data.weather.text |
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.
The condition
should be mapped to an entry from CONDITION_CLASSES
. This will make it possible in the future to show a visual representation of the condition in the frontend.
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.
Agreed, will add this.
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.
Done.
@property | ||
def name(self): | ||
"""Return the name of the sensor.""" | ||
return 'Met Office ({})'.format(self.site.name) |
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.
Using CONF_NAME
would give the user more flexibility.
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.
See comment on other name property review.
self._datapoint = datapoint | ||
self._site = site | ||
self.data = None | ||
self.lastupdate = LAST_UPDATE |
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.
Is this used?
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.
no, removed
if not site: | ||
_LOGGER.error("Unable to get nearest Met Office forecast site") | ||
return False | ||
else: |
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.
We can drop the else
and adjust the indent since the if statement returns False
.
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.
done
from homeassistant.components.weather import WeatherEntity, PLATFORM_SCHEMA | ||
from homeassistant.const import CONF_NAME, TEMP_CELSIUS | ||
from homeassistant.helpers import config_validation as cv | ||
# Reuse data and API logic from the sensor implementation |
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.
From my point of view it should be the other way around. The weather
platform should act as the primary implementation and the sensor
platform as a dependent.
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'm not sure I agree. I admit the reason I did it this way around is because it's the way the bom component did it. However it feels like the weather component is a collection of sensors, therefore it makes sense for the weather component to import the sensors.
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.
We created the weather
component to replace the sensor
platforms for meteorological data.
So, I tend to say that the weather
component should be the main implementation because there will be a frontend element some day and the sensor
platforms will be obsolete. But as we are moving slowing in this regard I will leave it up to you to decide what platform should be the main implementation.
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.
Thanks for explaining, makes a lot of sense. I'll update it so the weather
component is the primary.
|
||
from homeassistant.components.weather import WeatherEntity, PLATFORM_SCHEMA | ||
from homeassistant.const import CONF_NAME, TEMP_CELSIUS, CONF_API_KEY, | ||
CONF_LATITUDE, CONF_LONGITUDE |
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.
IndentationError: unexpected indent
unexpected indentation
datapoint = dp.connection(api_key=config.get(CONF_API_KEY)) | ||
|
||
latitude = config.get(CONF_LATITUDE, hass.config.latitude) | ||
longitude = config.get(CONF_LONGITUDE, hass.config.longitude) |
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.
undefined name 'CONF_LONGITUDE'
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.
Fixed
import datapoint as dp | ||
datapoint = dp.connection(api_key=config.get(CONF_API_KEY)) | ||
|
||
latitude = config.get(CONF_LATITUDE, hass.config.latitude) |
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.
undefined name 'CONF_LATITUDE'
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.
Fixed
@fabaff I've finished working through your review. There were three items I disagreed with or had questions about. Would you mind updating these? |
This is not working for me and a few others over on the forums. Where can I log an Issue with the developer? |
That would be me! Send me a link to the thread and I'll take a look.
…On Wed, 3 May 2017 at 18:58, cannfoddr ***@***.***> wrote:
This is not working for me and a few others over on the forums. Where can
I log an Issue with the developer?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6742 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABiUYvXlc8VKq0n3QEkQfy56gY37kiKeks5r2MBHgaJpZM4Mly_C>
.
|
Take a look here:
https://community.home-assistant.io/t/metoffice-integration/15537
…Sent from my iPhone
On 3 May 2017, at 19:39, Jacob Tomlinson ***@***.***> wrote:
That would be me! Send me a link to the thread and I'll take a look.
On Wed, 3 May 2017 at 18:58, cannfoddr ***@***.***> wrote:
> This is not working for me and a few others over on the forums. Where can
> I log an Issue with the developer?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#6742 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABiUYvXlc8VKq0n3QEkQfy56gY37kiKeks5r2MBHgaJpZM4Mly_C>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Take a look here:
https://community.home-assistant.io/t/metoffice-integration/15537 <https://community.home-assistant.io/t/metoffice-integration/15537>
… On 3 May 2017, at 19:39, Jacob Tomlinson ***@***.***> wrote:
That would be me! Send me a link to the thread and I'll take a look.
On Wed, 3 May 2017 at 18:58, cannfoddr ***@***.***> wrote:
> This is not working for me and a few others over on the forums. Where can
> I log an Issue with the developer?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#6742 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABiUYvXlc8VKq0n3QEkQfy56gY37kiKeks5r2MBHgaJpZM4Mly_C>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#6742 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AA_LOh1OKOUbCdabrCNxMbrF7beDrgfLks5r2MnTgaJpZM4Mly_C>.
|
Description:
Get weather data from the Met Office's DataPoint API.
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2318
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 passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.