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 Elk-M1 sensor platform #17342

Merged
merged 8 commits into from
Oct 19, 2018
Merged

Add Elk-M1 sensor platform #17342

merged 8 commits into from
Oct 19, 2018

Conversation

gwww
Copy link
Contributor

@gwww gwww commented Oct 11, 2018

Description:

See component PR for full details: #16952

Related issue (if applicable): fixes #

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

Example entry for configuration.yaml (if applicable):

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.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.elkm1/
"""

Copy link
Member

Choose a reason for hiding this comment

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

Remove blank line.

Copy link
Member

Choose a reason for hiding this comment

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

This is still left.

args = (service.data.get('number'))
_dispatch(SIGNAL_SPEAK_PHRASE, entity_ids, *args)

hass.services.async_register(DOMAIN, 'elkm1_sensor_speak_word',
Copy link
Member

Choose a reason for hiding this comment

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

Sensors are up until now read only, so we have never implemented any services for these platforms. Probably move the services to the elkm1 component. This is an architecture question.

I don't really see why these services belong to the sensor platform in the first place. "speak word" and "speak phrase" doesn't sound like something a sensor would do. More like a speaker. But I don't know this integration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can move the services. They seemed to be a better fit against the alarm panel rather than the entire config but serious don't know or care much as long as they can be easily invoked.

Copy link
Member

Choose a reason for hiding this comment

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

I suggest moving them to the component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you say move to the component, is that elkm1/__init__.py async_setup? Would I register the service as elkm1.speak_word, for example?

Copy link
Member

Choose a reason for hiding this comment

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

Yes!

def device_state_attributes(self):
"""Attributes of the sensor."""
attrs = self.initial_attrs()
attrs['elkm1_version'] = self._element.elkm1_version
Copy link
Member

Choose a reason for hiding this comment

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

Firmware version and similar info should go in device info, not state attributes. State attributes should hold data connected to the state of the device. device_info property requires config entries though so it's not super easy to implement. I suggest removing the version attributes for now.

https://developers.home-assistant.io/docs/en/device_registry_index.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've read those docs and was trying to figure out how it could be used with ElkM1. Not very clear at all how to do that integration. Some examples would be helpful in the docs. config_entries not very clear at all either. Does that mean everything that's in the elk section of configuration.yaml goes away?

So what to do? I'd like to keep the versions, implementing something else way over the top (to use your words "not super easy to implement").

What about the state associated with this entity? It tracks the state of the connection from hass to the actual platform. Is that in device_info?

Copy link
Member

Choose a reason for hiding this comment

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

We make a distinction between dynamic info and static info. Dynamic info belongs in state and state attributes as long as it pertains to the state of a device. Static info is... static so doesn't have to do with state of the device.

Static info like version has to be removed from state attributes.

If the connection has multiple states it can be in, then it fits as sensor state.

attrs = self.initial_attrs()
attrs['elkm1_version'] = self._element.elkm1_version
attrs['system_trouble_status'] = self._element.system_trouble_status
attrs['xep_version'] = self._element.xep_version
Copy link
Member

Choose a reason for hiding this comment

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

What is xep_version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the version of the Ethernet controller.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, then it has to be removed too.

return attrs


class ElkThermostat(ElkSensor):
Copy link
Member

Choose a reason for hiding this comment

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

Is this a pure read only integration, no temperature control? It should be a sensor and not a climate entity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sure I read, but cannot find right now, that each of the sensors of a device should be represented as separate entities. Thus this thermostat entity. Perhaps @BioSehnsucht can comment as I'm guessing he read the same thing from which code followed.

The next PR is for climate in which case the temperature will be available from that. Delete?

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 thermostat reading is the same device feature that will go in the climate entity, yes then remove this sensor type.

Copy link
Contributor

Choose a reason for hiding this comment

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

TL;DR : I think it's fine to remove the ElkThermostat sensors for now. When we get Omni protocol re-implemented to support the additional sensors, we can add those additional sensors back in.

At one time I had implemented the necessary protocol-within-a-protocol to be able to gather additional temperature sensors from Elk supported climate devices (specifically HAI Omnistat devices) which could have up to 4 temperature sensors in total (one of which was the thermostat itself). However at the moment we haven't re-implemented that again after switching from my library to @gwww 's so thermostat sensors are redundant, and once we re-implement the protocol inception necessary to support it, we can revisit and add just the 2nd-4th temp sensors as individual sensors. (In actuality, at the time, the thermostat sensor that was part of the climate entity was duplicated as a sensor because reasons ... so I always had duplicated sensors for climate)

homeassistant/components/sensor/elkm1.py Show resolved Hide resolved
"""
Support for control of ElkM1 sensors.

On the ElkM1 there are 6 types of sensors:
Copy link
Member

Choose a reason for hiding this comment

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

Move this to the docs.

@gwww
Copy link
Contributor Author

gwww commented Oct 16, 2018

Thank you for the review! Appreciate it.

'switch']

SPEAK_SERVICE_SCHEMA = vol.Schema({
vol.Required('number'): vol.Range(min=0, max=999),
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not validate only the range, but also the type (use float if necessary).

vol.Required('number'):
    vol.All(vol.Coerce(int), vol.Range(min=0, max=999)),

@@ -601,3 +601,17 @@ nest:
trip_id:
description: Optional identity of a trip. Using the same trip_ID will update the estimation.
example: trip_back_home

elkm1:
sensor_speak_word:
Copy link
Member

Choose a reason for hiding this comment

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

Move these to a new file services.yaml in the elkm1 package. See other components that are packages for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. Don't understand why though. What is different about elkm1 compared to the other services in where they were put?

Copy link
Member

Choose a reason for hiding this comment

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

We don't want to add more service descriptions to the base component package file.

The descriptions in the base component file are always loaded and cached the first time we need all the service descriptions of registered services, eg in the frontend, so the longer that file is the longer time it will take to do that, and the more information, potentially not needed info, will be stored in memory.

That's why we want to split this file up and put the descriptions in the other child components so that we only load the necessary information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that helps. Sounds like that the services will be eventually moved. Makes a lot of sense. Would it make sense to leave a "trail" in that services.yaml that says what you said in your comment? It could help point people in the right direction.

Copy link
Member

Choose a reason for hiding this comment

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

Make the suggestion in a PR. It should be documented in our dev docs at minimum.

@@ -0,0 +1,13 @@
elkm1:
Copy link
Member

Choose a reason for hiding this comment

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

Remove this key and unindent the following lines.

@@ -0,0 +1,13 @@
elkm1:
sensor_speak_word:
Copy link
Member

Choose a reason for hiding this comment

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

This is not the correct service name. Remove the sensor prefix.

@gwww
Copy link
Contributor Author

gwww commented Oct 19, 2018

Is this PR ready to merge? Thanks!

@MartinHjelmare MartinHjelmare merged commit 3655fef into home-assistant:dev Oct 19, 2018
@ghost ghost removed the in progress label Oct 19, 2018
@balloob balloob mentioned this pull request Oct 26, 2018
@gwww gwww deleted the elkm1-sensor branch November 12, 2018 15:15
@ghost ghost removed the platform: sensor.elkm1 label Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants