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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Volkszaehler sensor #16188

Merged
merged 3 commits into from
Aug 27, 2018
Merged

Add Volkszaehler sensor #16188

merged 3 commits into from
Aug 27, 2018

Conversation

fabaff
Copy link
Member

@fabaff fabaff commented Aug 25, 2018

Description:

Add support for consuming values exposed by the Volkszähler API.

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

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: volkszaehler
    host: demo.volkszaehler.org
    uuid: '57acbef0-88a9-11e4-934f-6b0f9ecd95a8'
    monitored_conditions:
      - average
      - consumption
      - min
      - max

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][ex-requir]).
  • New dependencies are only imported inside functions that use them ([example][ex-import]).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

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.

Nice! Just some small comments.

host = config.get(CONF_HOST)
name = config.get(CONF_NAME)
port = config.get(CONF_PORT)
uuid = config.get(CONF_UUID)
Copy link
Member

Choose a reason for hiding this comment

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

Use dict[key] for required config keys.

self._name = name
self.type = sensor_type
self._state = None
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this attribute? Icon doesn't use a dedicated attribute.

Copy link
Member Author

Choose a reason for hiding this comment

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

No.

await self.vz_api.async_update()

if self.vz_api.api.data is not None:
if self.type == 'average':
Copy link
Member

Choose a reason for hiding this comment

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

We could use getattr:

self._state = round(getattr(self.vz_api.api, self.type), 2)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks

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.

🎉

@MartinHjelmare MartinHjelmare merged commit c51170e into dev Aug 27, 2018
@ghost ghost removed the in progress label Aug 27, 2018
@fabaff fabaff deleted the volkszaehler branch August 27, 2018 13:20
mbennett pushed a commit to mbennett/home-assistant that referenced this pull request Aug 27, 2018
* Add Volkszaehler sensor

* Update icons

* Improve code
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
* Add Volkszaehler sensor

* Update icons

* Improve code
@balloob balloob mentioned this pull request Sep 17, 2018
@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.

None yet

3 participants