Skip to content

Season sensor#8958

Merged
pvizeli merged 1 commit into
home-assistant:devfrom
w1ll1am23:season_sensor
Aug 29, 2017
Merged

Season sensor#8958
pvizeli merged 1 commit into
home-assistant:devfrom
w1ll1am23:season_sensor

Conversation

@w1ll1am23
Copy link
Copy Markdown
Contributor

@w1ll1am23 w1ll1am23 commented Aug 13, 2017

Description:

This sensor will display the current astronomical or meteorological season (Spring, Summer, Autumn, Winter) based on the users setting in the config file.

All information about how the seasons work was taken from Wikipedia:
https://en.wikipedia.org/wiki/Season#Astronomical
https://en.wikipedia.org/wiki/Equinox
https://en.wikipedia.org/wiki/Solstice

I don't expect this to be very useful for anyone in tropical regions because their seasons aren't really anything like the reset of the world. Maybe someone that knows more about that can add support for them? Wet/Dry seasons?

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: season
    type: astronomical (optional, will default to astronomical) 

Checklist:

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

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

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.

@mention-bot
Copy link
Copy Markdown

@w1ll1am23, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabaff and @rmkraus to be potential reviewers.

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no newline at end of file

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread requirements_all.txt Outdated
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 not be part of this pr

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.

Hmm not sure how that got there, all I did was run gen_requirements_all.py

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.

Please don't use STATE_UNKNOWN, instead use None and let Home Assistant handle unknown states.

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 that a nice cleanup would be to extract this method from this class and just make it a method in this file . Have it pass datetime as a parameter.

That way it will make your tests also a lot easier, you can test the method directly.

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.

It would be faster to create datetimes and just replace the year instead of going via strings

image

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.

Is it really necessary to have all the datetimes of starting points of seasons, couldn't you just check versus the month ?

if 6 <= datetime.month < 9:
    season = STATE_SUMMER

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.

This is because the seasons don't start with the month. For example this year the first day of fall in the northern hemisphere is 9/22 but in 2019 it will be on 9/23. That is of course if the user is using astronomical seasons.

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.

Oh good point

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'DEVICE'
line too long (95 > 79 characters)

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'DEVICE'
line too long (95 > 79 characters)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (80 > 79 characters)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'homeassistant.const.STATE_UNKNOWN' imported but unused

@w1ll1am23
Copy link
Copy Markdown
Contributor Author

@balloob I think I have addressed all of your suggestions.

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread tests/components/sensor/test_season.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

@pvizeli pvizeli merged commit 3e0eb87 into home-assistant:dev Aug 29, 2017
@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented Aug 29, 2017

I think you can convert this into a async component in future

matemaciek added a commit to matemaciek/home-assistant that referenced this pull request Aug 30, 2017
* upstream/dev: (113 commits)
  Fix fitbit error when trying to access token after upgrade. (home-assistant#9183)
  Upgrade sendgrid to 5.0.1 (home-assistant#9215)
  Upgrade pyasn1 to 0.3.3 and pyasn1-modules to 0.1.1 (home-assistant#9216)
  directv: extended discovery via REST api, bug fix  (home-assistant#8800)
  Bayesian Binary Sensor (home-assistant#8810)
  Add cloud auth support (home-assistant#9208)
  Abode push events and lock, cover, and switch components (home-assistant#9095)
  Lint Sonarr tests
  Upgrade pymysensors to 0.11.1 (home-assistant#9212)
  Refactor rfxtrx (home-assistant#9117)
  Issue home-assistant#6893 in rfxtrx (home-assistant#9130)
  Support for season sensor (home-assistant#8958)
  Add counter component (home-assistant#9146)
  Fix and optimize digitalloggers platform (home-assistant#9203)
  Prevent error when no forecast data was available (home-assistant#9176)
  Add "status" to Sonarr sensor (home-assistant#9204)
  fix worldtidesinfo home-assistant#9184 (home-assistant#9201)
  Update pushbullet.py (home-assistant#9200)
  Fix dht22 when no data was read initially home-assistant#8976 (home-assistant#9198)
  Prevent iCloud exceptions in logfile (home-assistant#9179)
  ...
@balloob balloob mentioned this pull request Sep 7, 2017
@balloob
Copy link
Copy Markdown
Member

balloob commented Sep 9, 2017

This PR did not include documentation 😞

@w1ll1am23
Copy link
Copy Markdown
Contributor Author

Dang, you are right I totally forgot. I'll try to get that added in the next day or two.

@balloob
Copy link
Copy Markdown
Member

balloob commented Sep 9, 2017

I've added a stub now since it's release day.

@home-assistant home-assistant locked and limited conversation to collaborators Dec 11, 2017
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