Skip to content

Netatmo public#15684

Merged
fabaff merged 9 commits intohome-assistant:devfrom
colinfrei:netatmo-public
Aug 13, 2018
Merged

Netatmo public#15684
fabaff merged 9 commits intohome-assistant:devfrom
colinfrei:netatmo-public

Conversation

@colinfrei
Copy link
Copy Markdown
Contributor

@colinfrei colinfrei commented Jul 25, 2018

Description:

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5893

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: netatmo_public
    areas:
      - lat_ne: 40.719
        lon_ne: -73.735
        lat_sw: 40.552
        lon_sw: -74.105

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

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

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

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@colinfrei
Copy link
Copy Markdown
Contributor Author

I linked my git@ email address to github as well, hope the cla-bot rechecks that automatically :)

@homeassistant
Copy link
Copy Markdown
Contributor

Hi @colinfrei,

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!

@Danielhiversen
Copy link
Copy Markdown
Member

Are all the public sensors for rain? Never temperature?

@colinfrei
Copy link
Copy Markdown
Contributor Author

I use the rain sensors, which is why I added those, temperature and some others would be available as well.

@Danielhiversen
Copy link
Copy Markdown
Member

Ok, so where are you specifying that you get rain data or is that default?

Copy link
Copy Markdown
Member

@Danielhiversen Danielhiversen left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. This will be a useful component.

I have added some comments.
You also got some comments on your documentation: home-assistant/home-assistant.io#5893 (comment)



def calculate_average(raindata):
"""Get the average value in the area."""
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.

Why not use sum(raindata.values()) / len(raindata) ?

LAT_NE=self.lat_ne,
LON_NE=self.lon_ne,
LAT_SW=self.lat_sw,
LON_SW=self.lon_sw)
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.

Add required_data_type = "rain" to make it obvious that you ask for rain data

self._state = self.netatmo_data.data


class NetatmoPublicData(object):
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.

This NetatmoPublicData class is not needed when we only support rain data

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would it be ok to leave it since I'd expect that to expand to additional metrics soon?

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.

I think so. Would be nice with other sensors too.


if raindata.CountStationInArea() == 0:
_LOGGER.warning('No Rain Station available in this area.')
else:
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.

Use return here, and skip the else:


def calculate_max(raindata):
"""Get the highest value in the area."""
key_max = max(raindata.keys(), key=(lambda k: raindata[k]))
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.

Why not max(raindata.values()) ?

raindata_live = raindata.getLive()

if self.calculation == 'avg':
self.data = calculate_average(raindata_live)
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.

Not necessary to calculate_average as a separate function.

if self.calculation == 'avg':
self.data = calculate_average(raindata_live)
else:
self.data = calculate_max(raindata_live)
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.

Not necessary to calculate_max as a separate function.

LON_NE=self.lon_ne,
LAT_SW=self.lat_sw,
LON_SW=self.lon_sw,
required_data_type = "rain")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected spaces around keyword / parameter equals

@christ0ph
Copy link
Copy Markdown

Ah, this one would be so usefull!

Copy link
Copy Markdown
Member

@Danielhiversen Danielhiversen left a comment

Choose a reason for hiding this comment

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

LGTM. 🎉
Just remove the error logging line
And fix the style error: https://travis-ci.org/home-assistant/home-assistant/jobs/412315360#L565

self._state = self.netatmo_data.data


class NetatmoPublicData(object):
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.

I think so. Would be nice with other sensors too.


raindata_live = raindata.getLive()

_LOGGER.error(raindata_live.values())
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.

Should be removed?

@colinfrei
Copy link
Copy Markdown
Contributor Author

Fixed :)

@fabaff fabaff merged commit f411fb8 into home-assistant:dev Aug 13, 2018
@ghost ghost removed the in progress label Aug 13, 2018
def update(self):
"""Request an update from the Netatmo API."""
import pyatmo
_LOGGER.error('Updating Netatmo data.')
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.

Wrong log level. We can remove this all together.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

definitely - not sure how that sneaked in.
Fixed here: #15966

@colinfrei colinfrei mentioned this pull request Aug 14, 2018
8 tasks
@balloob balloob mentioned this pull request Aug 29, 2018
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
* Add a sensor for netatmo public data

* A bit of cleanup before submitting pull request

* Add netatmo_public file to .coveragerc, as per pull request template instructions

* Fixes for tox complaining

* make calculations simpler, based on review feedback

* explicitly pass required_data parameter to netatmo API

* remove unnecessary spaces

* remove debug code

* code style fix
vrih pushed a commit to vrih/home-assistant that referenced this pull request Sep 29, 2018
* Add a sensor for netatmo public data

* A bit of cleanup before submitting pull request

* Add netatmo_public file to .coveragerc, as per pull request template instructions

* Fixes for tox complaining

* make calculations simpler, based on review feedback

* explicitly pass required_data parameter to netatmo API

* remove unnecessary spaces

* remove debug code

* code style fix
@home-assistant home-assistant locked and limited conversation to collaborators Dec 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants