Skip to content
Merged
Show file tree
Hide file tree
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 Mar 31, 2019
0be274e
Update coveragerc
mitchellrj Mar 31, 2019
bc0a530
Simplify attributes
mitchellrj Mar 31, 2019
83cda85
Remove config option
mitchellrj Apr 1, 2019
698a3a3
Refactor and document device-ness and update mechanism
mitchellrj Apr 1, 2019
81602f0
Entity docstrings
mitchellrj Apr 1, 2019
cf8e655
Remove lingering config for sensors
mitchellrj Apr 1, 2019
ce8f251
Whitespace
mitchellrj Apr 1, 2019
8c358aa
Remove redundant entity ID generation and hass assignment.
mitchellrj Apr 1, 2019
ab83b54
More meaningful variable name.
mitchellrj Apr 1, 2019
d1a13fb
Add new 'not-darkness' pseudo-sensor.
mitchellrj Apr 1, 2019
a32a84c
Refactor sensors into separate binary, non-binary, and shared modules.
mitchellrj Apr 1, 2019
3c87828
formatting
mitchellrj Apr 1, 2019
5ca133d
make linter happy.
mitchellrj Apr 2, 2019
38d3b3d
Refactor again, fix update mechanism, and address comments.
mitchellrj Apr 7, 2019
0f02e71
Remove unnecessary assignment
mitchellrj Apr 7, 2019
5e1584b
Small fixes.
mitchellrj Apr 7, 2019
a2aa946
docstring
mitchellrj Apr 7, 2019
ac80fc0
Another refactor: only call API once and make testing easier
mitchellrj Apr 10, 2019
4ba490e
Tests & test fixes
mitchellrj Apr 10, 2019
4b5bb8d
Flake & lint
mitchellrj Apr 10, 2019
41dff19
Use gather and dispatcher
mitchellrj Apr 10, 2019
5883e16
Remove unnecessary whitespace change.
mitchellrj Apr 10, 2019
c6633fb
Move component related stuff out of the shared module
mitchellrj Apr 10, 2019
4ee15fc
Remove unused remnant of failed approach.
mitchellrj Apr 10, 2019
f291a62
Increase test coverage
mitchellrj Apr 12, 2019
74fb6f1
Don't get too upset if we're already trying to update an entity befor…
mitchellrj Apr 13, 2019
9958a6f
relative imports
balloob Apr 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions homeassistant/components/hue/binary_sensor.py
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(
Comment thread
mitchellrj marked this conversation as resolved.
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
16 changes: 14 additions & 2 deletions homeassistant/components/hue/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ async def async_setup(self, tries=0):

hass.async_create_task(hass.config_entries.async_forward_entry_setup(
self.config_entry, 'light'))
hass.async_create_task(hass.config_entries.async_forward_entry_setup(
Comment thread
mitchellrj marked this conversation as resolved.
self.config_entry, 'binary_sensor'))
hass.async_create_task(hass.config_entries.async_forward_entry_setup(
self.config_entry, 'sensor'))

hass.services.async_register(
DOMAIN, SERVICE_HUE_SCENE, self.hue_activate_scene,
Expand All @@ -94,8 +98,16 @@ async def async_reset(self):

# If setup was successful, we set api variable, forwarded entry and
# register service
return await self.hass.config_entries.async_forward_entry_unload(
self.config_entry, 'light')
results = await asyncio.gather(
self.hass.config_entries.async_forward_entry_unload(
self.config_entry, 'light'),
self.hass.config_entries.async_forward_entry_unload(
self.config_entry, 'binary_sensor'),
self.hass.config_entries.async_forward_entry_unload(
self.config_entry, 'sensor')
)
# None and True are OK
return False not in results

async def hue_activate_scene(self, call, updated=False):
"""Service to call directly into bridge to set scenes."""
Expand Down
57 changes: 57 additions & 0 deletions homeassistant/components/hue/sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Hue sensor entities."""
from homeassistant.const import (
Comment thread
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
Comment thread
mitchellrj marked this conversation as resolved.
attributes.update({
"threshold_dark": self.sensor.tholddark,
Comment thread
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
Loading