Skip to content

Commit c476500

Browse files
authored
Fix Shelly n_current sensor removal condition (home-assistant#148740)
1 parent f65fa38 commit c476500

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

homeassistant/components/shelly/sensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,8 @@ def __init__(
868868
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
869869
device_class=SensorDeviceClass.CURRENT,
870870
state_class=SensorStateClass.MEASUREMENT,
871-
available=lambda status: (status and status["n_current"]) is not None,
872-
removal_condition=lambda _config, status, _key: "n_current" not in status,
871+
removal_condition=lambda _config, status, key: status[key].get("n_current")
872+
is None,
873873
entity_registry_enabled_default=False,
874874
),
875875
"total_current": RpcSensorDescription(

tests/components/shelly/fixtures/pro_3em.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
"c_pf": 0.72,
152152
"c_voltage": 230.2,
153153
"id": 0,
154-
"n_current": null,
154+
"n_current": 3.124,
155155
"total_act_power": 2413.825,
156156
"total_aprt_power": 2525.779,
157157
"total_current": 11.116,

tests/components/shelly/snapshots/test_devices.ambr

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4303,6 +4303,62 @@
43034303
'state': '230.2',
43044304
})
43054305
# ---
4306+
# name: test_shelly_pro_3em[sensor.test_name_phase_n_current-entry]
4307+
EntityRegistryEntrySnapshot({
4308+
'aliases': set({
4309+
}),
4310+
'area_id': None,
4311+
'capabilities': dict({
4312+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
4313+
}),
4314+
'config_entry_id': <ANY>,
4315+
'config_subentry_id': <ANY>,
4316+
'device_class': None,
4317+
'device_id': <ANY>,
4318+
'disabled_by': None,
4319+
'domain': 'sensor',
4320+
'entity_category': None,
4321+
'entity_id': 'sensor.test_name_phase_n_current',
4322+
'has_entity_name': True,
4323+
'hidden_by': None,
4324+
'icon': None,
4325+
'id': <ANY>,
4326+
'labels': set({
4327+
}),
4328+
'name': None,
4329+
'options': dict({
4330+
'sensor': dict({
4331+
'suggested_display_precision': 2,
4332+
}),
4333+
}),
4334+
'original_device_class': <SensorDeviceClass.CURRENT: 'current'>,
4335+
'original_icon': None,
4336+
'original_name': 'Phase N current',
4337+
'platform': 'shelly',
4338+
'previous_unique_id': None,
4339+
'suggested_object_id': None,
4340+
'supported_features': 0,
4341+
'translation_key': None,
4342+
'unique_id': '123456789ABC-em:0-n_current',
4343+
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
4344+
})
4345+
# ---
4346+
# name: test_shelly_pro_3em[sensor.test_name_phase_n_current-state]
4347+
StateSnapshot({
4348+
'attributes': ReadOnlyDict({
4349+
'device_class': 'current',
4350+
'friendly_name': 'Test name Phase N current',
4351+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
4352+
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
4353+
}),
4354+
'context': <ANY>,
4355+
'entity_id': 'sensor.test_name_phase_n_current',
4356+
'last_changed': <ANY>,
4357+
'last_reported': <ANY>,
4358+
'last_updated': <ANY>,
4359+
'state': '3.124',
4360+
})
4361+
# ---
43064362
# name: test_shelly_pro_3em[sensor.test_name_rssi-entry]
43074363
EntityRegistryEntrySnapshot({
43084364
'aliases': set({

0 commit comments

Comments
 (0)