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

Add Brottsplatskartan sensor #19018

Merged
merged 9 commits into from Dec 16, 2018

Conversation

Projects
None yet
5 participants
@chrillux
Copy link
Contributor

chrillux commented Dec 4, 2018

Description:

Add sensor for brottsplatskartan.se

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

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: brottsplatskartan

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

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.
@homeassistant

This comment has been minimized.

Copy link

homeassistant commented Dec 4, 2018

Hi @chrillux,

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!

Show resolved Hide resolved lol.py Outdated
Show resolved Hide resolved lol.py Outdated

@chrillux chrillux force-pushed the chrillux:brottsplatskartan branch from ea1ca73 to 5be9bd0 Dec 5, 2018

@chrillux chrillux force-pushed the chrillux:brottsplatskartan branch from 5be9bd0 to 9baa553 Dec 10, 2018

@MartinHjelmare
Copy link
Member

MartinHjelmare left a comment

Looks good! One question.

vol.Inclusive(CONF_LATITUDE, 'coordinates'): cv.latitude,
vol.Inclusive(CONF_LONGITUDE, 'coordinates'): cv.longitude,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_AREA, default=''): cv.string,

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Dec 10, 2018

Member

What kind of area is this? Is it possible to validate?

This comment has been minimized.

@chrillux

chrillux Dec 14, 2018

Contributor

I found out that there is an endpoint that lists all the areas: https://brottsplatskartan.se/api/areas and added some validation for the area parameter against these areas. Hope it is the hass way to do it. :)

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Dec 15, 2018

Member

This isn't correct. Do we need to have the empty string as default?

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Dec 15, 2018

Member

Each item should have one key and one validator. If we need to use multiple validators we can use vol.All or vol.Any, eg.

This comment has been minimized.

@chrillux

chrillux Dec 16, 2018

Contributor

Maybe I'm not understanding the documentation fully when it says: "Starting with Home Assistant 0.64 voluptuous requires default values for optional configuration keys to be valid values. Don't use a default which is None like vol.Optional(CONF_SOMETHING, default=None): cv.string, set the default to default='' if required.". That's why I set the value there to an empty string.

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Dec 16, 2018

Member

Empty list as default will pass the validation, so that's good.

@chrillux chrillux force-pushed the chrillux:brottsplatskartan branch from 9baa553 to 0dcd4dc Dec 14, 2018

@MartinHjelmare
Copy link
Member

MartinHjelmare left a comment

Good!

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Inclusive(CONF_LATITUDE, 'coordinates'): cv.latitude,
vol.Inclusive(CONF_LONGITUDE, 'coordinates'): cv.longitude,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_AREA, default=''): cv.string,
vol.Optional(CONF_AREA, default=''):

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Dec 15, 2018

Member

The default has to pass validation too.

This comment has been minimized.

@chrillux

chrillux Dec 15, 2018

Contributor

Thanks!

Not sure what I should validate here. I updated the code again to check if area is defined but empty, then it will raise validation errors. Is that what you meant?

chrillux added some commits Dec 4, 2018

Update brottsplatskartan sensor
* Remove redundant configuration checks.
* Set attributes during initialization.
* Setup brottsplatskartan module in setup_platform().
* Just do a simple return, no need for returning false.
More updates to brottsplatskartan
* Import uuid at the top of the module.
* Use sensor as domain.
* Don't fire custom events.
* Remove period from logging message.

@chrillux chrillux force-pushed the chrillux:brottsplatskartan branch from 0dcd4dc to 2865ab1 Dec 15, 2018

@MartinHjelmare
Copy link
Member

MartinHjelmare left a comment

The config schema needs to be fixed.

@MartinHjelmare
Copy link
Member

MartinHjelmare left a comment

Awesome!

@MartinHjelmare MartinHjelmare changed the title Added Brottsplatskartan sensor Add Brottsplatskartan sensor Dec 16, 2018

@MartinHjelmare MartinHjelmare merged commit c26c8af into home-assistant:dev Dec 16, 2018

5 checks passed

Hound No violations found. Woof!
WIP Legacy commit status override — see details
Details
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.0008%) to 92.879%
Details

@wafflebot wafflebot bot removed the in progress label Dec 16, 2018

@chrillux

This comment has been minimized.

Copy link
Contributor

chrillux commented Dec 16, 2018

Thanks Martin for the help and reviewing!

dshokouhi added a commit to dshokouhi/home-assistant that referenced this pull request Dec 25, 2018

Add Brottsplatskartan sensor (home-assistant#19018)
* Added brottsplatskartan sensor

* Update brottsplatskartan sensor

* Remove redundant configuration checks.
* Set attributes during initialization.
* Setup brottsplatskartan module in setup_platform().
* Just do a simple return, no need for returning false.

* Remove file that was used during testing

* Better variable name and remove excessive newline.

* More updates to brottsplatskartan

* Import uuid at the top of the module.
* Use sensor as domain.
* Don't fire custom events.
* Remove period from logging message.

* Adding validation for area parameter

* Validate empty area configuration

* Fixing indentation.

* Fixing the config schema

@balloob balloob referenced this pull request Jan 10, 2019

Merged

0.85.0 #19897

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment