diff --git a/homeassistant/components/smartthings/sensor.py b/homeassistant/components/smartthings/sensor.py index d3e2ab09a3fd..42581a2807e5 100644 --- a/homeassistant/components/smartthings/sensor.py +++ b/homeassistant/components/smartthings/sensor.py @@ -1151,8 +1151,11 @@ async def async_setup_entry( ) and ( not description.exists_fn - or description.exists_fn( - device.status[MAIN][capability][attribute] + or ( + component == MAIN + and description.exists_fn( + device.status[MAIN][capability][attribute] + ) ) ) and ( diff --git a/tests/components/smartthings/conftest.py b/tests/components/smartthings/conftest.py index c45417122e92..a68bbba22d21 100644 --- a/tests/components/smartthings/conftest.py +++ b/tests/components/smartthings/conftest.py @@ -166,6 +166,7 @@ def mock_smartthings() -> Generator[AsyncMock]: "hw_q80r_soundbar", "gas_meter", "lumi", + "tesla_powerwall", ] ) def device_fixture( diff --git a/tests/components/smartthings/fixtures/device_status/tesla_powerwall.json b/tests/components/smartthings/fixtures/device_status/tesla_powerwall.json new file mode 100644 index 000000000000..c9531314d5fe --- /dev/null +++ b/tests/components/smartthings/fixtures/device_status/tesla_powerwall.json @@ -0,0 +1,107 @@ +{ + "components": { + "charge": { + "powerMeter": { + "power": { + "value": 0, + "unit": "W", + "timestamp": "2025-10-02T12:21:29.196Z" + } + }, + "powerConsumptionReport": { + "powerConsumption": { + "value": { + "start": "2025-10-02T12:20:00Z", + "end": "2025-10-02T12:25:00Z", + "energy": 29765947, + "deltaEnergy": 0 + }, + "timestamp": "2025-10-02T12:26:24.729Z" + } + } + }, + "discharge": { + "powerMeter": { + "power": { + "value": 0, + "unit": "W", + "timestamp": "2025-10-02T11:41:20.556Z" + } + }, + "powerConsumptionReport": { + "powerConsumption": { + "value": { + "start": "2025-10-02T12:20:00Z", + "end": "2025-10-02T12:25:00Z", + "energy": 27827062, + "deltaEnergy": 0 + }, + "timestamp": "2025-10-02T12:26:24.729Z" + } + } + }, + "main": { + "healthCheck": { + "checkInterval": { + "value": 60, + "unit": "s", + "data": { + "deviceScheme": "UNTRACKED", + "protocol": "cloud" + }, + "timestamp": "2025-10-02T11:56:25.223Z" + }, + "healthStatus": { + "value": null + }, + "DeviceWatch-Enroll": { + "value": null + }, + "DeviceWatch-DeviceStatus": { + "value": "online", + "data": {}, + "timestamp": "2025-10-02T11:56:25.223Z" + } + }, + "rivertalent14263.adaptiveEnergyUsageState": { + "stormWatchEnabled": { + "value": true, + "timestamp": "2024-07-16T12:40:19.190Z" + }, + "stormWatchActive": { + "value": false, + "timestamp": "2024-07-16T12:40:19.190Z" + }, + "gridStatusSupport": { + "value": true, + "timestamp": "2024-07-16T12:40:19.190Z" + }, + "stormWatchSupport": { + "value": true, + "timestamp": "2025-09-17T18:31:31.669Z" + }, + "energyUsageState": { + "value": null + }, + "gridStatusStatus": { + "value": "on-grid", + "timestamp": "2025-09-17T18:31:31.669Z" + } + }, + "refresh": {}, + "battery": { + "quantity": { + "value": null + }, + "battery": { + "value": 35, + "unit": "%", + "timestamp": "2025-10-02T11:41:20.556Z" + }, + "type": { + "value": null + } + } + } + } +} diff --git a/tests/components/smartthings/fixtures/devices/tesla_powerwall.json b/tests/components/smartthings/fixtures/devices/tesla_powerwall.json new file mode 100644 index 000000000000..20e11a353554 --- /dev/null +++ b/tests/components/smartthings/fixtures/devices/tesla_powerwall.json @@ -0,0 +1,103 @@ +{ + "items": [ + { + "deviceId": "d2595c45-df6e-41ac-a7af-8e275071c19b", + "name": "UDHN-TESLA-ENERGY-BATTERY", + "label": "Powerwall", + "manufacturerName": "0AHI", + "presentationId": "STES-1-PV-TESLA-ENERGY-BATTERY", + "locationId": "d22d6401-6070-4928-8e7b-b724e2dbf425", + "ownerId": "35445a41-3ae2-4bc0-6f51-31705de6b96f", + "components": [ + { + "id": "main", + "label": "main", + "capabilities": [ + { + "id": "healthCheck", + "version": 1 + }, + { + "id": "refresh", + "version": 1 + }, + { + "id": "rivertalent14263.adaptiveEnergyUsageState", + "version": 1 + }, + { + "id": "battery", + "version": 1 + } + ], + "categories": [ + { + "name": "Battery", + "categoryType": "manufacturer" + } + ], + "optional": false + }, + { + "id": "discharge", + "label": "discharge", + "capabilities": [ + { + "id": "powerConsumptionReport", + "version": 1 + }, + { + "id": "powerMeter", + "version": 1 + } + ], + "categories": [ + { + "name": "Other", + "categoryType": "manufacturer" + } + ], + "optional": false + }, + { + "id": "charge", + "label": "charge", + "capabilities": [ + { + "id": "powerConsumptionReport", + "version": 1 + }, + { + "id": "powerMeter", + "version": 1 + } + ], + "categories": [ + { + "name": "Other", + "categoryType": "manufacturer" + } + ], + "optional": false + } + ], + "createTime": "2024-07-16T12:40:18.632Z", + "profile": { + "id": "4f9998dc-e672-4baf-8521-5e9b853fc978" + }, + "app": { + "installedAppId": "e798c0a6-3e3b-4299-8463-438fc3f1e6b3", + "externalId": "TESLABATTERY_1689188152863574", + "profile": { + "id": "4f9998dc-e672-4baf-8521-5e9b853fc978" + } + }, + "type": "ENDPOINT_APP", + "restrictionTier": 0, + "allowed": null, + "executionContext": "CLOUD", + "relationships": [] + } + ], + "_links": {} +} diff --git a/tests/components/smartthings/snapshots/test_init.ambr b/tests/components/smartthings/snapshots/test_init.ambr index 5cd56c316839..42eaf548b36d 100644 --- a/tests/components/smartthings/snapshots/test_init.ambr +++ b/tests/components/smartthings/snapshots/test_init.ambr @@ -1893,6 +1893,37 @@ 'via_device_id': None, }) # --- +# name: test_devices[tesla_powerwall] + DeviceRegistryEntrySnapshot({ + 'area_id': None, + 'config_entries': , + 'config_entries_subentries': , + 'configuration_url': 'https://account.smartthings.com', + 'connections': set({ + }), + 'disabled_by': None, + 'entry_type': None, + 'hw_version': None, + 'id': , + 'identifiers': set({ + tuple( + 'smartthings', + 'd2595c45-df6e-41ac-a7af-8e275071c19b', + ), + }), + 'labels': set({ + }), + 'manufacturer': None, + 'model': None, + 'model_id': None, + 'name': 'Powerwall', + 'name_by_user': None, + 'primary_config_entry': , + 'serial_number': None, + 'sw_version': None, + 'via_device_id': None, + }) +# --- # name: test_devices[tplink_p110] DeviceRegistryEntrySnapshot({ 'area_id': None, diff --git a/tests/components/smartthings/snapshots/test_sensor.ambr b/tests/components/smartthings/snapshots/test_sensor.ambr index 9e83fdacab91..c573ccbbc27a 100644 --- a/tests/components/smartthings/snapshots/test_sensor.ambr +++ b/tests/components/smartthings/snapshots/test_sensor.ambr @@ -13969,6 +13969,56 @@ 'state': '20', }) # --- +# name: test_all_entities[tesla_powerwall][sensor.powerwall_battery-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.powerwall_battery', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Battery', + 'platform': 'smartthings', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'd2595c45-df6e-41ac-a7af-8e275071c19b_main_battery_battery_battery', + 'unit_of_measurement': '%', + }) +# --- +# name: test_all_entities[tesla_powerwall][sensor.powerwall_battery-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'battery', + 'friendly_name': 'Powerwall Battery', + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.powerwall_battery', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '35', + }) +# --- # name: test_all_entities[tplink_p110][sensor.spulmaschine_energy-entry] EntityRegistryEntrySnapshot({ 'aliases': set({