-
-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Add Device Pairing Enabled binary sensor to Lyric integration #177062
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
Changes from 5 commits
6ba33ba
950804d
87dad02
31dd000
7a25c55
d9569d4
bd4198c
fb2ffaf
5b11c9e
710edce
9325ce6
d0c6e8b
2e1cda0
26e0d7a
7b5b5b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| """Support for Honeywell Lyric binary sensor platform.""" | ||
|
|
||
| from collections.abc import Callable | ||
| from dataclasses import dataclass | ||
| from typing import override | ||
|
|
||
| from aiolyric.objects.device import LyricDevice | ||
| from aiolyric.objects.location import LyricLocation | ||
| from aiolyric.objects.priority import LyricAccessory, LyricRoom | ||
|
|
||
| from homeassistant.components.binary_sensor import ( | ||
| BinarySensorDeviceClass, | ||
| BinarySensorEntity, | ||
| BinarySensorEntityDescription, | ||
| ) | ||
| from homeassistant.const import EntityCategory | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback | ||
|
|
||
| from .coordinator import LyricConfigEntry, LyricDataUpdateCoordinator | ||
| from .entity import LyricAccessoryEntity, LyricDeviceEntity | ||
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class LyricBinarySensorEntityDescription(BinarySensorEntityDescription): | ||
| """Class describing Honeywell Lyric binary sensor entities.""" | ||
|
|
||
| value_fn: Callable[[LyricDevice], bool] | ||
| suitable_fn: Callable[[LyricDevice], bool] | ||
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class LyricBinarySensorAccessoryEntityDescription(BinarySensorEntityDescription): | ||
| """Class describing Honeywell Lyric room sensor binary sensor entities.""" | ||
|
|
||
| value_fn: Callable[[LyricRoom, LyricAccessory], bool] | ||
| suitable_fn: Callable[[LyricRoom, LyricAccessory], bool] | ||
|
|
||
|
|
||
| DEVICE_BINARY_SENSORS: list[LyricBinarySensorEntityDescription] = [ | ||
| LyricBinarySensorEntityDescription( | ||
| key="vacation_hold", | ||
| translation_key="vacation_hold", | ||
| value_fn=lambda device: device.vacation_hold.enabled, | ||
| suitable_fn=lambda device: True, | ||
| ), | ||
| LyricBinarySensorEntityDescription( | ||
| key="device_pairing_enabled", | ||
| translation_key="device_pairing_enabled", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| value_fn=lambda device: device.settings.device_pairing_enabled, | ||
| suitable_fn=lambda device: True, | ||
| ), | ||
| ] | ||
|
|
||
| ACCESSORY_BINARY_SENSORS: list[LyricBinarySensorAccessoryEntityDescription] = [ | ||
| LyricBinarySensorAccessoryEntityDescription( | ||
| key="room_motion", | ||
| translation_key="room_motion", | ||
| device_class=BinarySensorDeviceClass.MOTION, | ||
| value_fn=lambda _, accessory: accessory.detect_motion, | ||
| suitable_fn=lambda _, accessory: accessory.type == "IndoorAirSensor", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, and already tracked — this needs timmo001/aiolyric#165 (the currentPriority/priority and type/sensorType field fix) merged and released before Room Motion populates for real accounts. Filing it as a dependency rather than blocking on it here, since #165 is a separate project on its own release cycle, and this PR is still correct/complete for what core can control. Once #165 releases, the follow-up is a one-line manifest.json version bump — tracked separately. |
||
| ), | ||
| ] | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, | ||
| entry: LyricConfigEntry, | ||
| async_add_entities: AddConfigEntryEntitiesCallback, | ||
| ) -> None: | ||
|
Comment on lines
+41
to
+45
|
||
| """Set up the Honeywell Lyric binary sensor platform based on a config entry.""" | ||
| coordinator = entry.runtime_data | ||
|
|
||
| async_add_entities( | ||
| LyricBinarySensor( | ||
| coordinator, | ||
| device_binary_sensor, | ||
| location, | ||
| device, | ||
| ) | ||
| for location in coordinator.data.locations | ||
| for device in location.devices | ||
| for device_binary_sensor in DEVICE_BINARY_SENSORS | ||
| if device_binary_sensor.suitable_fn(device) | ||
| ) | ||
|
|
||
| async_add_entities( | ||
| LyricAccessoryBinarySensor( | ||
| coordinator, binary_sensor, location, device, room, accessory | ||
| ) | ||
| for location in coordinator.data.locations | ||
| for device in location.devices | ||
| for room in coordinator.data.rooms_dict.get(device.mac_id, {}).values() | ||
| for accessory in room.accessories | ||
| for binary_sensor in ACCESSORY_BINARY_SENSORS | ||
| if binary_sensor.suitable_fn(room, accessory) | ||
| ) | ||
|
|
||
|
|
||
| class LyricBinarySensor(LyricDeviceEntity, BinarySensorEntity): | ||
| """Define a Honeywell Lyric binary sensor.""" | ||
|
|
||
| entity_description: LyricBinarySensorEntityDescription | ||
|
|
||
| def __init__( | ||
| self, | ||
| coordinator: LyricDataUpdateCoordinator, | ||
| description: LyricBinarySensorEntityDescription, | ||
| location: LyricLocation, | ||
| device: LyricDevice, | ||
| ) -> None: | ||
| """Initialize.""" | ||
| super().__init__( | ||
| coordinator, | ||
| location, | ||
| device, | ||
| f"{device.mac_id}_{description.key}", | ||
| ) | ||
| self.entity_description = description | ||
|
|
||
| @property | ||
| @override | ||
| def is_on(self) -> bool: | ||
| """Return true if the condition is met.""" | ||
| return self.entity_description.value_fn(self.device) | ||
|
|
||
|
|
||
| class LyricAccessoryBinarySensor(LyricAccessoryEntity, BinarySensorEntity): | ||
| """Define a Honeywell Lyric room sensor binary sensor.""" | ||
|
|
||
| entity_description: LyricBinarySensorAccessoryEntityDescription | ||
|
|
||
| def __init__( | ||
| self, | ||
| coordinator: LyricDataUpdateCoordinator, | ||
| description: LyricBinarySensorAccessoryEntityDescription, | ||
| location: LyricLocation, | ||
| parentDevice: LyricDevice, | ||
| room: LyricRoom, | ||
| accessory: LyricAccessory, | ||
| ) -> None: | ||
| """Initialize.""" | ||
| super().__init__( | ||
| coordinator, | ||
| location, | ||
| parentDevice, | ||
| room, | ||
| accessory, | ||
| f"{parentDevice.mac_id}_room{room.id}_acc{accessory.id}_{description.key}", | ||
| ) | ||
| self.entity_description = description | ||
|
|
||
| @property | ||
| @override | ||
| def is_on(self) -> bool: | ||
| """Return true if motion is detected.""" | ||
| return self.entity_description.value_fn(self.room, self.accessory) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,17 @@ | |
| } | ||
| }, | ||
| "entity": { | ||
| "binary_sensor": { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Link to documentation pull request: home-assistant/home-assistant.io#46986 |
||
| "device_pairing_enabled": { | ||
| "name": "Device pairing enabled" | ||
| }, | ||
| "room_motion": { | ||
| "name": "Room motion" | ||
| }, | ||
| "vacation_hold": { | ||
| "name": "Vacation hold" | ||
| } | ||
| }, | ||
| "select": { | ||
| "room_priority": { | ||
| "name": "Room priority", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed — good catch. vacationHold.Enabled (capital E) is what Resideo actually returns; I have a live captured payload showing it. Fixed in timmo001/aiolyric here: clutch2sft/aiolyric#170 (branch fix-vacation-hold-key).