-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Add basic support for native Hue sensors #22598
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
Merged
balloob
merged 28 commits into
home-assistant:dev
from
mitchellrj:add-basic-hue-sensor-support
Apr 18, 2019
Merged
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9d93c43
Add basic support for native Hue sensors
mitchellrj 0be274e
Update coveragerc
mitchellrj bc0a530
Simplify attributes
mitchellrj 83cda85
Remove config option
mitchellrj 698a3a3
Refactor and document device-ness and update mechanism
mitchellrj 81602f0
Entity docstrings
mitchellrj cf8e655
Remove lingering config for sensors
mitchellrj ce8f251
Whitespace
mitchellrj 8c358aa
Remove redundant entity ID generation and hass assignment.
mitchellrj ab83b54
More meaningful variable name.
mitchellrj d1a13fb
Add new 'not-darkness' pseudo-sensor.
mitchellrj a32a84c
Refactor sensors into separate binary, non-binary, and shared modules.
mitchellrj 3c87828
formatting
mitchellrj 5ca133d
make linter happy.
mitchellrj 38d3b3d
Refactor again, fix update mechanism, and address comments.
mitchellrj 0f02e71
Remove unnecessary assignment
mitchellrj 5e1584b
Small fixes.
mitchellrj a2aa946
docstring
mitchellrj ac80fc0
Another refactor: only call API once and make testing easier
mitchellrj 4ba490e
Tests & test fixes
mitchellrj 4b5bb8d
Flake & lint
mitchellrj 41dff19
Use gather and dispatcher
mitchellrj 5883e16
Remove unnecessary whitespace change.
mitchellrj c6633fb
Move component related stuff out of the shared module
mitchellrj 4ee15fc
Remove unused remnant of failed approach.
mitchellrj f291a62
Increase test coverage
mitchellrj 74fb6f1
Don't get too upset if we're already trying to update an entity befor…
mitchellrj 9958a6f
relative imports
balloob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """Hue binary sensor entities.""" | ||
| from homeassistant.components.binary_sensor import BinarySensorDevice | ||
| from homeassistant.components.hue.sensor_base import ( | ||
| GenericZLLSensor, async_setup_entry as shared_async_setup_entry) | ||
|
|
||
|
|
||
| PRESENCE_NAME_FORMAT = "{} presence" | ||
|
|
||
|
|
||
| async def async_setup_entry(hass, config_entry, async_add_entities): | ||
| """Defer binary sensor setup to the shared sensor module.""" | ||
| await shared_async_setup_entry( | ||
| hass, config_entry, async_add_entities, binary=True) | ||
|
|
||
|
|
||
| class HuePresence(GenericZLLSensor, BinarySensorDevice): | ||
| """The presence sensor entity for a Hue motion sensor device.""" | ||
|
|
||
| device_class = 'presence' | ||
|
|
||
| async def _async_update_ha_state(self, *args, **kwargs): | ||
| await self.async_update_ha_state(self, *args, **kwargs) | ||
|
|
||
| @property | ||
| def is_on(self): | ||
| """Return true if the binary sensor is on.""" | ||
| return self.sensor.presence | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| """Hue sensor entities.""" | ||
| from homeassistant.const import ( | ||
|
mitchellrj marked this conversation as resolved.
|
||
| DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS) | ||
| from homeassistant.helpers.entity import Entity | ||
| from homeassistant.components.hue.sensor_base import ( | ||
| GenericZLLSensor, async_setup_entry as shared_async_setup_entry) | ||
|
|
||
|
|
||
| LIGHT_LEVEL_NAME_FORMAT = "{} light level" | ||
| TEMPERATURE_NAME_FORMAT = "{} temperature" | ||
|
|
||
|
|
||
| async def async_setup_entry(hass, config_entry, async_add_entities): | ||
| """Defer sensor setup to the shared sensor module.""" | ||
| await shared_async_setup_entry( | ||
| hass, config_entry, async_add_entities, binary=False) | ||
|
|
||
|
|
||
| class GenericHueGaugeSensorEntity(GenericZLLSensor, Entity): | ||
| """Parent class for all 'gauge' Hue device sensors.""" | ||
|
|
||
| async def _async_update_ha_state(self, *args, **kwargs): | ||
| await self.async_update_ha_state(self, *args, **kwargs) | ||
|
|
||
|
|
||
| class HueLightLevel(GenericHueGaugeSensorEntity): | ||
| """The light level sensor entity for a Hue motion sensor device.""" | ||
|
|
||
| device_class = DEVICE_CLASS_ILLUMINANCE | ||
| unit_of_measurement = "Lux" | ||
|
|
||
| @property | ||
| def state(self): | ||
| """Return the state of the device.""" | ||
| return self.sensor.lightlevel | ||
|
|
||
| @property | ||
| def device_state_attributes(self): | ||
| """Return the device state attributes.""" | ||
| attributes = super().device_state_attributes | ||
|
mitchellrj marked this conversation as resolved.
|
||
| attributes.update({ | ||
| "threshold_dark": self.sensor.tholddark, | ||
|
mitchellrj marked this conversation as resolved.
|
||
| "threshold_offset": self.sensor.tholdoffset, | ||
| }) | ||
| return attributes | ||
|
|
||
|
|
||
| class HueTemperature(GenericHueGaugeSensorEntity): | ||
| """The temperature sensor entity for a Hue motion sensor device.""" | ||
|
|
||
| device_class = DEVICE_CLASS_TEMPERATURE | ||
| unit_of_measurement = TEMP_CELSIUS | ||
|
|
||
| @property | ||
| def state(self): | ||
| """Return the state of the device.""" | ||
| return self.sensor.temperature / 100 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.