binary_sensor sensor_class to entity device_class#5860
Conversation
|
@armills, thanks for your PR! By analyzing the history of the files in this pull request, we identified @fabaff, @pvizeli and @MartinHjelmare to be potential reviewers. |
| state = self.hass.states.get(self.entity.entity_id) | ||
| assert state.attributes.get(ATTR_DEVICE_CLASS) == None | ||
| with patch('homeassistant.helpers.entity.Entity.device_class', | ||
| new='test_class'): |
There was a problem hiding this comment.
continuation line over-indented for visual indent
| def test_device_class(self): | ||
| """Test device class attribute.""" | ||
| state = self.hass.states.get(self.entity.entity_id) | ||
| assert state.attributes.get(ATTR_DEVICE_CLASS) == None |
There was a problem hiding this comment.
comparison to None should be 'if cond is None:'
MartinHjelmare
left a comment
There was a problem hiding this comment.
I like this! Looks good besides the lint errors.
| vol.Optional(CONF_PAYLOAD_OFF, default=DEFAULT_PAYLOAD_OFF): cv.string, | ||
| vol.Optional(CONF_PAYLOAD_ON, default=DEFAULT_PAYLOAD_ON): cv.string, | ||
| vol.Optional(CONF_SENSOR_CLASS, default=None): | ||
| vol.Any(vol.In(SENSOR_CLASSES), vol.SetTo(None)), |
There was a problem hiding this comment.
So I'm not sure why the schema was set up like this before. Is there a specific reason we want to silently ignore invalid classes?
There was a problem hiding this comment.
That's weird, we shouldn't. I have never seen SetTo before. (quick grep shows this is the only place it is used)
|
Love it! 🐬 amazing job. |
|
This seemed to break the UI icons for binary sensor templates. Is that just me? |
|
I had to clear the cache to get it to update. |
|
Ah yep that did the trick. Thanks Adam. |
Description:
This PR changes the binary_sensor property
sensor_classto an Entity propertydevice_class. I think this type of classification could be beneficial to expand to other components. My intended use case is to add this functionality to the cover component. Some examples being garage, window, door, gate, etc. I'm sure this could be useful for other components as well, though.See also:
home-assistant/frontend#200
home-assistant/home-assistant.io#2005