-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Add Accessory Status sensor to Lyric integration #177064
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
Open
clutch2sft
wants to merge
2
commits into
home-assistant:dev
Choose a base branch
from
clutch2sft:sensor-accessory-status
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| SensorEntityDescription, | ||
| SensorStateClass, | ||
| ) | ||
| from homeassistant.const import PERCENTAGE, UnitOfTemperature | ||
| from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfTemperature | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback | ||
| from homeassistant.helpers.typing import StateType | ||
|
|
@@ -133,6 +133,13 @@ class LyricSensorAccessoryEntityDescription(SensorEntityDescription): | |
| value_fn=lambda room, _: room.room_avg_humidity, | ||
| suitable_fn=lambda _, accessory: accessory.type == "IndoorAirSensor", | ||
| ), | ||
| LyricSensorAccessoryEntityDescription( | ||
| key="accessory_status", | ||
| translation_key="accessory_status", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| value_fn=lambda _, accessory: accessory.status, | ||
|
Comment on lines
+136
to
+140
Comment on lines
+136
to
+140
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. Documentation added/updated for www.home-assistant.io |
||
| suitable_fn=lambda _, accessory: accessory.type == "IndoorAirSensor", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
|
|
||
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 |
|---|---|---|
| @@ -1 +1,13 @@ | ||
| """Tests for the Honeywell Lyric integration.""" | ||
|
|
||
| from homeassistant.core import HomeAssistant | ||
|
|
||
| from tests.common import MockConfigEntry | ||
|
|
||
|
|
||
| async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) -> None: | ||
| """Set up the Lyric integration for tests.""" | ||
| config_entry.add_to_hass(hass) | ||
|
|
||
| await hass.config_entries.async_setup(config_entry.entry_id) | ||
| await hass.async_block_till_done() |
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,76 @@ | ||
| """Fixtures for the Honeywell Lyric integration tests.""" | ||
|
|
||
| from collections.abc import Generator | ||
| from time import time | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from aiolyric.objects.location import LyricLocation | ||
| from aiolyric.objects.priority import LyricRoom | ||
| import pytest | ||
|
|
||
| from homeassistant.components.application_credentials import ( | ||
| DOMAIN as APPLICATION_CREDENTIALS_DOMAIN, | ||
| ClientCredential, | ||
| async_import_client_credential, | ||
| ) | ||
| from homeassistant.components.lyric.const import DOMAIN | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.setup import async_setup_component | ||
|
|
||
| from tests.common import ( | ||
| MockConfigEntry, | ||
| load_json_array_fixture, | ||
| load_json_object_fixture, | ||
| ) | ||
|
|
||
| CLIENT_ID = "1234" | ||
| CLIENT_SECRET = "5678" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def setup_credentials(hass: HomeAssistant) -> None: | ||
| """Register lyric application credentials.""" | ||
| assert await async_setup_component(hass, APPLICATION_CREDENTIALS_DOMAIN, {}) | ||
|
|
||
| await async_import_client_credential( | ||
| hass, DOMAIN, ClientCredential(CLIENT_ID, CLIENT_SECRET) | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_config_entry() -> MockConfigEntry: | ||
| """Return an already-authenticated Lyric config entry.""" | ||
| return MockConfigEntry( | ||
| domain=DOMAIN, | ||
| data={ | ||
| "auth_implementation": DOMAIN, | ||
| "token": { | ||
| "access_token": "mock-access-token", | ||
| "refresh_token": "mock-refresh-token", | ||
| "expires_at": time() + 3600, | ||
| "token_type": "Bearer", | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_lyric_api() -> Generator[MagicMock]: | ||
| """Mock the aiolyric client, backed by real Location/Room objects parsed from live-shaped fixtures.""" | ||
| with patch("homeassistant.components.lyric.Lyric", autospec=True) as mock_lyric_cls: | ||
| lyric = mock_lyric_cls.return_value | ||
|
|
||
| locations_json = load_json_array_fixture("locations.json", DOMAIN) | ||
| lyric.locations = [ | ||
| LyricLocation(MagicMock(), location) for location in locations_json | ||
| ] | ||
| lyric.locations_dict = { | ||
| location.location_id: location for location in lyric.locations | ||
| } | ||
|
|
||
| room_json = load_json_object_fixture("room.json", DOMAIN) | ||
| room = LyricRoom(room_json) | ||
| mac_id = lyric.locations[0].devices[0].mac_id | ||
| lyric.rooms_dict = {mac_id: {room.id: room}} | ||
|
|
||
| yield lyric |
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,22 @@ | ||
| [ | ||
| { | ||
| "locationID": 35202000168931, | ||
| "name": "Ocala P01", | ||
| "devices": [ | ||
| { | ||
| "vacationHold": { "Enabled": true }, | ||
| "scheduleStatus": "Resume", | ||
| "settings": { "devicePairingEnabled": true }, | ||
| "deviceClass": "Thermostat", | ||
| "deviceType": "Thermostat", | ||
| "deviceID": "LCC-7f86b153-8480-f111-b78f-6045bdb25006", | ||
| "name": "Ocala", | ||
| "macID": "5CFCE1B67035", | ||
| "units": "Fahrenheit", | ||
| "indoorTemperature": 79, | ||
| "deviceModel": "T9-T10" | ||
| } | ||
| ], | ||
| "users": [] | ||
| } | ||
| ] |
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,15 @@ | ||
| { | ||
| "id": 1, | ||
| "roomName": "Primary Bedroom", | ||
| "roomAvgTemp": 74.5, | ||
| "roomAvgHumidity": 54, | ||
| "accessories": [ | ||
| { | ||
| "id": 1, | ||
| "type": "IndoorAirSensor", | ||
| "temperature": 74.5, | ||
| "status": "Ok", | ||
| "detectMotion": true | ||
| } | ||
| ] | ||
| } |
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,222 @@ | ||
| # serializer version: 1 | ||
| # name: test_sensor[sensor.ocala_thermostat_indoor_temperature-entry] | ||
| EntityRegistryEntrySnapshot({ | ||
| 'aliases': list([ | ||
| None, | ||
| ]), | ||
| 'area_id': None, | ||
| 'capabilities': dict({ | ||
| <SensorEntityCapabilityAttribute.STATE_CLASS: 'state_class'>: <SensorStateClass.MEASUREMENT: 'measurement'>, | ||
| }), | ||
| 'config_entry_id': <ANY>, | ||
| 'config_subentry_id': <ANY>, | ||
| 'device_class': None, | ||
| 'device_id': <ANY>, | ||
| 'disabled_by': None, | ||
| 'domain': 'sensor', | ||
| 'entity_category': None, | ||
| 'entity_id': 'sensor.ocala_thermostat_indoor_temperature', | ||
| 'has_entity_name': True, | ||
| 'hidden_by': None, | ||
| 'icon': None, | ||
| 'id': <ANY>, | ||
| 'labels': set({ | ||
| }), | ||
| 'name': None, | ||
| 'object_id_base': 'Indoor temperature', | ||
| 'options': dict({ | ||
| 'sensor': dict({ | ||
| 'suggested_display_precision': 1, | ||
| }), | ||
| }), | ||
| 'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>, | ||
| 'original_icon': None, | ||
| 'original_name': 'Indoor temperature', | ||
| 'platform': 'lyric', | ||
| 'previous_unique_id': None, | ||
| 'suggested_object_id': None, | ||
| 'supported_features': 0, | ||
| 'translation_key': 'indoor_temperature', | ||
| 'unique_id': '5CFCE1B67035_indoor_temperature', | ||
| 'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>, | ||
| }) | ||
| # --- | ||
| # name: test_sensor[sensor.ocala_thermostat_indoor_temperature-state] | ||
| StateSnapshot({ | ||
| 'attributes': ReadOnlyDict({ | ||
| <EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'temperature', | ||
| <EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Ocala Thermostat Indoor temperature', | ||
| <SensorEntityCapabilityAttribute.STATE_CLASS: 'state_class'>: <SensorStateClass.MEASUREMENT: 'measurement'>, | ||
| <EntityStateAttribute.UNIT_OF_MEASUREMENT: 'unit_of_measurement'>: <UnitOfTemperature.CELSIUS: '°C'>, | ||
| }), | ||
| 'context': <ANY>, | ||
| 'entity_id': 'sensor.ocala_thermostat_indoor_temperature', | ||
| 'last_changed': <ANY>, | ||
| 'last_reported': <ANY>, | ||
| 'last_updated': <ANY>, | ||
| 'state': '26.1111111111111', | ||
| }) | ||
| # --- | ||
| # name: test_sensor[sensor.primary_bedroom_sensor_accessory_status-entry] | ||
| EntityRegistryEntrySnapshot({ | ||
| 'aliases': list([ | ||
| None, | ||
| ]), | ||
| 'area_id': None, | ||
| 'capabilities': None, | ||
| 'config_entry_id': <ANY>, | ||
| 'config_subentry_id': <ANY>, | ||
| 'device_class': None, | ||
| 'device_id': <ANY>, | ||
| 'disabled_by': None, | ||
| 'domain': 'sensor', | ||
| 'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>, | ||
| 'entity_id': 'sensor.primary_bedroom_sensor_accessory_status', | ||
| 'has_entity_name': True, | ||
| 'hidden_by': None, | ||
| 'icon': None, | ||
| 'id': <ANY>, | ||
| 'labels': set({ | ||
| }), | ||
| 'name': None, | ||
| 'object_id_base': 'Accessory status', | ||
| 'options': dict({ | ||
| }), | ||
| 'original_device_class': None, | ||
| 'original_icon': None, | ||
| 'original_name': 'Accessory status', | ||
| 'platform': 'lyric', | ||
| 'previous_unique_id': None, | ||
| 'suggested_object_id': None, | ||
| 'supported_features': 0, | ||
| 'translation_key': 'accessory_status', | ||
| 'unique_id': '5CFCE1B67035_room1_acc1_accessory_status', | ||
| 'unit_of_measurement': None, | ||
| }) | ||
| # --- | ||
| # name: test_sensor[sensor.primary_bedroom_sensor_accessory_status-state] | ||
| StateSnapshot({ | ||
| 'attributes': ReadOnlyDict({ | ||
| <EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Primary Bedroom Sensor Accessory status', | ||
| }), | ||
| 'context': <ANY>, | ||
| 'entity_id': 'sensor.primary_bedroom_sensor_accessory_status', | ||
| 'last_changed': <ANY>, | ||
| 'last_reported': <ANY>, | ||
| 'last_updated': <ANY>, | ||
| 'state': 'Ok', | ||
| }) | ||
| # --- | ||
| # name: test_sensor[sensor.primary_bedroom_sensor_room_humidity-entry] | ||
| EntityRegistryEntrySnapshot({ | ||
| 'aliases': list([ | ||
| None, | ||
| ]), | ||
| 'area_id': None, | ||
| 'capabilities': dict({ | ||
| <SensorEntityCapabilityAttribute.STATE_CLASS: 'state_class'>: <SensorStateClass.MEASUREMENT: 'measurement'>, | ||
| }), | ||
| 'config_entry_id': <ANY>, | ||
| 'config_subentry_id': <ANY>, | ||
| 'device_class': None, | ||
| 'device_id': <ANY>, | ||
| 'disabled_by': None, | ||
| 'domain': 'sensor', | ||
| 'entity_category': None, | ||
| 'entity_id': 'sensor.primary_bedroom_sensor_room_humidity', | ||
| 'has_entity_name': True, | ||
| 'hidden_by': None, | ||
| 'icon': None, | ||
| 'id': <ANY>, | ||
| 'labels': set({ | ||
| }), | ||
| 'name': None, | ||
| 'object_id_base': 'Room humidity', | ||
| 'options': dict({ | ||
| }), | ||
| 'original_device_class': <SensorDeviceClass.HUMIDITY: 'humidity'>, | ||
| 'original_icon': None, | ||
| 'original_name': 'Room humidity', | ||
| 'platform': 'lyric', | ||
| 'previous_unique_id': None, | ||
| 'suggested_object_id': None, | ||
| 'supported_features': 0, | ||
| 'translation_key': 'room_humidity', | ||
| 'unique_id': '5CFCE1B67035_room1_acc1_room_humidity', | ||
| 'unit_of_measurement': '%', | ||
| }) | ||
| # --- | ||
| # name: test_sensor[sensor.primary_bedroom_sensor_room_humidity-state] | ||
| StateSnapshot({ | ||
| 'attributes': ReadOnlyDict({ | ||
| <EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'humidity', | ||
| <EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Primary Bedroom Sensor Room humidity', | ||
| <SensorEntityCapabilityAttribute.STATE_CLASS: 'state_class'>: <SensorStateClass.MEASUREMENT: 'measurement'>, | ||
| <EntityStateAttribute.UNIT_OF_MEASUREMENT: 'unit_of_measurement'>: '%', | ||
| }), | ||
| 'context': <ANY>, | ||
| 'entity_id': 'sensor.primary_bedroom_sensor_room_humidity', | ||
| 'last_changed': <ANY>, | ||
| 'last_reported': <ANY>, | ||
| 'last_updated': <ANY>, | ||
| 'state': '54', | ||
| }) | ||
| # --- | ||
| # name: test_sensor[sensor.primary_bedroom_sensor_room_temperature-entry] | ||
| EntityRegistryEntrySnapshot({ | ||
| 'aliases': list([ | ||
| None, | ||
| ]), | ||
| 'area_id': None, | ||
| 'capabilities': dict({ | ||
| <SensorEntityCapabilityAttribute.STATE_CLASS: 'state_class'>: <SensorStateClass.MEASUREMENT: 'measurement'>, | ||
| }), | ||
| 'config_entry_id': <ANY>, | ||
| 'config_subentry_id': <ANY>, | ||
| 'device_class': None, | ||
| 'device_id': <ANY>, | ||
| 'disabled_by': None, | ||
| 'domain': 'sensor', | ||
| 'entity_category': None, | ||
| 'entity_id': 'sensor.primary_bedroom_sensor_room_temperature', | ||
| 'has_entity_name': True, | ||
| 'hidden_by': None, | ||
| 'icon': None, | ||
| 'id': <ANY>, | ||
| 'labels': set({ | ||
| }), | ||
| 'name': None, | ||
| 'object_id_base': 'Room temperature', | ||
| 'options': dict({ | ||
| 'sensor': dict({ | ||
| 'suggested_display_precision': 1, | ||
| }), | ||
| }), | ||
| 'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>, | ||
| 'original_icon': None, | ||
| 'original_name': 'Room temperature', | ||
| 'platform': 'lyric', | ||
| 'previous_unique_id': None, | ||
| 'suggested_object_id': None, | ||
| 'supported_features': 0, | ||
| 'translation_key': 'room_temperature', | ||
| 'unique_id': '5CFCE1B67035_room1_acc1_room_temperature', | ||
| 'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>, | ||
| }) | ||
| # --- | ||
| # name: test_sensor[sensor.primary_bedroom_sensor_room_temperature-state] | ||
| StateSnapshot({ | ||
| 'attributes': ReadOnlyDict({ | ||
| <EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'temperature', | ||
| <EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Primary Bedroom Sensor Room temperature', | ||
| <SensorEntityCapabilityAttribute.STATE_CLASS: 'state_class'>: <SensorStateClass.MEASUREMENT: 'measurement'>, | ||
| <EntityStateAttribute.UNIT_OF_MEASUREMENT: 'unit_of_measurement'>: <UnitOfTemperature.CELSIUS: '°C'>, | ||
| }), | ||
| 'context': <ANY>, | ||
| 'entity_id': 'sensor.primary_bedroom_sensor_room_temperature', | ||
| 'last_changed': <ANY>, | ||
| 'last_reported': <ANY>, | ||
| 'last_updated': <ANY>, | ||
| 'state': '23.6111111111111', | ||
| }) | ||
| # --- |
Oops, something went wrong.
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.
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.
What are the possible options? If it's a finite list, we should make this an enum device class and return the possible options so we can make a better experience
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.
Good question — I actually went and checked. Resideo's own API schema for this endpoint doesn't document a status field on accessories at all (only id, type, excludeTemp, excludeMotion, temperature are documented; status shows up in practice but isn't in their spec). The only value I've ever observed, across my own live capture and aiolyric's test fixtures, is "Ok" — I have no second data point.
Given that, I'd rather not enum-ify it yet: if I lock in options=["Ok"] and a sensor actually goes offline/errors (exactly the failure mode this diagnostic sensor exists to surface), HA would treat that unlisted value as invalid instead of showing it — which defeats the point. Happy to switch to SensorDeviceClass.ENUM the moment we have real evidence of the full value set, but I don't want to guess it into an incomplete enum right now.