Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add brightsky weather entity #37800

Closed
wants to merge 1 commit into from
Closed

Conversation

mweinelt
Copy link
Contributor

@mweinelt mweinelt commented Jul 12, 2020

Breaking change

Proposed change

Add support for DWD weather data using the Bright Sky API.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

TODOs

Notes

  • It's violating the rule about requests to external services being outsourced into dedicated Python Packages. That makes little sense to me for ~60 LOC that do two HTTP GET requests and very little else.

@frenck
Copy link
Member

frenck commented Jul 13, 2020

We no longer accept integrations, that connect with a device or service, to be configured via YAML.
See: https://github.com/home-assistant/architecture/blob/master/adr/0010-integration-configuration.md#decision

Please add a configuration flow to this integration, see our developers documentation for more information: https://developers.home-assistant.io/docs/config_entries_config_flow_handler

Thanks already 馃憤

Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Adding review comment to correct the state of this PR.

@frenck frenck added this to Incoming in New Integrations via automation Aug 3, 2020
@frenck frenck moved this from Incoming to Awaiting Requested Changes in New Integrations Aug 3, 2020
@mweinelt mweinelt marked this pull request as ready for review August 3, 2020 21:24
@mweinelt
Copy link
Contributor Author

mweinelt commented Aug 3, 2020

I have this in a somewhat working state and have been using it for a couple of weeks. I have no clue if what I've done with the config flow and its test is sensible.

The API currently has the limitation of only relying on data collected from stations, filled up with data from other stations, when the closest station does not offer a certain feature. This means that data like the weather condition could come from a station as much as 30km away.

Another limitation is that there is no interpolation of data in relation to the distance one has to the next station. So the data has to be taken with a grain of salt.

My next station is 3 km away across the city and the values measured are spot on, so there is certainly some value.

@RobBie1221
Copy link
Contributor

It's violating the rule about requests to external services being outsourced into dedicated Python Packages. That makes little sense to me for ~60 LOC that do two HTTP GET requests and very little else.

The developer docs mention that all API specific code should be part of a third party library. It's not just about 2 HTTP GET requests, you are mapping brightsky keys to ha keys here, which is API specific code. That should be put in a separate library such that when API's change, ha only needs a dependency bump and the logic can be changed in the third party library.

@disrupted
Copy link

There's an official library on PyPI for brightsky now: https://pypi.org/project/brightsky/

@mweinelt
Copy link
Contributor Author

mweinelt commented Sep 9, 2020

I wouldn't recommend running your own brightsky instance, when there is an API that can be easily queried.

@RobBie1221 Okay, rescheduling work on this for some time in october, can't get to it earlier than that.

@RobBie1221
Copy link
Contributor

API specific code needs to abstracted to a package hosted on PyPi. @disrupted is pointing to an existing package which can be used.

@disrupted
Copy link

I might've gotten it wrong. Looks like the PyPI package is for running your own instance as @mweinelt noted. If we just want to query the official instance https://brightsky.dev/ I guess we should build a wrapper around that or ask the developer if he's planning to make this functionality available within the brightsky package.

@stale
Copy link

stale bot commented Oct 12, 2020

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@stale stale bot added the stale label Oct 12, 2020
@mweinelt
Copy link
Contributor Author

I'm working on separating API access and hass integration right now.

@mweinelt
Copy link
Contributor Author

mweinelt commented Oct 19, 2020

Published hass-brightsky-client at https://pypi.org/project/hass-brightsky-client/ and updated the component to make use of the library.

Untested as of yet.

@mweinelt

This comment has been minimized.

@mweinelt

This comment has been minimized.

@mweinelt
Copy link
Contributor Author

Squashed and rebased.

@mweinelt
Copy link
Contributor Author

API specific code needs to abstracted to a package hosted on PyPi. @disrupted is pointing to an existing package which can be used.

This was fixed.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Please exclude non tested modules from coverage by including them in .coveragerc. Only the config flow requires 100 % coverage, although more tests are appreciated.

Comment on lines +11 to +12
CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)

try:
info = await validate_input(self.hass, user_input)

return self.async_create_entry(title=info["title"], data=user_input)
Copy link
Member

Choose a reason for hiding this comment

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

Please only wrap the line than can raise in the try... except block. Use and else: block if needed.

vol.Required(
CONF_LONGITUDE, default=self.hass.config.longitude
): cv.longitude,
vol.Optional(CONF_MODE, default="hourly"): vol.In(FORECAST_MODE),
Copy link
Member

Choose a reason for hiding this comment

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

If this option isn't required for the connection it should be moved to an options flow instead of the main flow.

@@ -0,0 +1,11 @@
{
"domain": "brightsky",
Copy link
Member

Choose a reason for hiding this comment

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

We normally separate words with underscore.

Suggested change
"domain": "brightsky",
"domain": "bright_sky",

"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
Copy link
Member

Choose a reason for hiding this comment

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

This string isn't used.

return self._name

@property
def state(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

Don't implement state. Implement the condition property.

return items

@Throttle(UPDATE_INTERVAL)
def update(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

"homeassistant.components.brightsky.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure(
Copy link
Member

Choose a reason for hiding this comment

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

We need to patch the library here to avoid I/O.

@mweinelt
Copy link
Contributor Author

Sorry, I've lost interest in completing this.

@mweinelt mweinelt closed this Feb 27, 2021
Dev automation moved this from Review in progress to Cancelled Feb 27, 2021
New Integrations automation moved this from Awaiting Requested Changes to Cancelled Feb 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Dev
  
Cancelled
New Integrations
  
Cancelled
Development

Successfully merging this pull request may close these issues.

None yet

6 participants