forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor of Hue integration with full V2 support (home-assistant#58996)
Co-authored-by: Paulus Schoutsen <[email protected]>
- Loading branch information
1 parent
4642a70
commit e1e6925
Showing
55 changed files
with
7,163 additions
and
2,272 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains 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 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 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 |
---|---|---|
@@ -1,56 +1,24 @@ | ||
"""Hue binary sensor entities.""" | ||
from aiohue.sensors import TYPE_ZLL_PRESENCE | ||
|
||
from homeassistant.components.binary_sensor import ( | ||
DEVICE_CLASS_MOTION, | ||
BinarySensorEntity, | ||
) | ||
|
||
from .const import DOMAIN as HUE_DOMAIN | ||
from .sensor_base import SENSOR_CONFIG_MAP, GenericZLLSensor | ||
|
||
PRESENCE_NAME_FORMAT = "{} motion" | ||
|
||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
"""Defer binary sensor setup to the shared sensor module.""" | ||
bridge = hass.data[HUE_DOMAIN][config_entry.entry_id] | ||
|
||
if not bridge.sensor_manager: | ||
return | ||
|
||
await bridge.sensor_manager.async_register_component( | ||
"binary_sensor", async_add_entities | ||
) | ||
|
||
|
||
class HuePresence(GenericZLLSensor, BinarySensorEntity): | ||
"""The presence sensor entity for a Hue motion sensor device.""" | ||
|
||
_attr_device_class = DEVICE_CLASS_MOTION | ||
|
||
@property | ||
def is_on(self): | ||
"""Return true if the binary sensor is on.""" | ||
return self.sensor.presence | ||
|
||
@property | ||
def extra_state_attributes(self): | ||
"""Return the device state attributes.""" | ||
attributes = super().extra_state_attributes | ||
if "sensitivity" in self.sensor.config: | ||
attributes["sensitivity"] = self.sensor.config["sensitivity"] | ||
if "sensitivitymax" in self.sensor.config: | ||
attributes["sensitivity_max"] = self.sensor.config["sensitivitymax"] | ||
return attributes | ||
|
||
|
||
SENSOR_CONFIG_MAP.update( | ||
{ | ||
TYPE_ZLL_PRESENCE: { | ||
"platform": "binary_sensor", | ||
"name_format": PRESENCE_NAME_FORMAT, | ||
"class": HuePresence, | ||
} | ||
} | ||
) | ||
"""Support for Hue binary sensors.""" | ||
from __future__ import annotations | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .bridge import HueBridge | ||
from .const import DOMAIN | ||
from .v1.binary_sensor import async_setup_entry as setup_entry_v1 | ||
from .v2.binary_sensor import async_setup_entry as setup_entry_v2 | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up binary sensor entities.""" | ||
bridge: HueBridge = hass.data[DOMAIN][config_entry.entry_id] | ||
if bridge.api_version == 1: | ||
await setup_entry_v1(hass, config_entry, async_add_entities) | ||
else: | ||
await setup_entry_v2(hass, config_entry, async_add_entities) |
Oops, something went wrong.