Skip to content

Commit 21f24c2

Browse files
catsmanacabmantis
andauthored
Get Enphase_envoy collar grid status from admin_state_str rather then from grid_state (home-assistant#153766)
Co-authored-by: Abílio Costa <[email protected]>
1 parent 85b2647 commit 21f24c2

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

homeassistant/components/enphase_envoy/icons.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@
3838
},
3939
"available_energy": {
4040
"default": "mdi:battery-50"
41+
},
42+
"grid_status": {
43+
"default": "mdi:transmission-tower",
44+
"state": {
45+
"off_grid": "mdi:transmission-tower-off",
46+
"synchronizing": "mdi:sync-alert"
47+
}
48+
},
49+
"mid_state": {
50+
"default": "mdi:electric-switch-closed",
51+
"state": {
52+
"open": "mdi:electric-switch"
53+
}
54+
},
55+
"admin_state": {
56+
"default": "mdi:transmission-tower",
57+
"state": {
58+
"off_grid": "mdi:transmission-tower-off"
59+
}
4160
}
4261
},
4362
"switch": {

homeassistant/components/enphase_envoy/sensor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,12 @@ class EnvoyCollarSensorEntityDescription(SensorEntityDescription):
824824
value_fn: Callable[[EnvoyCollar], datetime.datetime | int | float | str]
825825

826826

827+
# translations don't accept uppercase
828+
ADMIN_STATE_MAP = {
829+
"ENCMN_MDE_ON_GRID": "on_grid",
830+
"ENCMN_MDE_OFF_GRID": "off_grid",
831+
}
832+
827833
COLLAR_SENSORS = (
828834
EnvoyCollarSensorEntityDescription(
829835
key="temperature",
@@ -838,11 +844,21 @@ class EnvoyCollarSensorEntityDescription(SensorEntityDescription):
838844
device_class=SensorDeviceClass.TIMESTAMP,
839845
value_fn=lambda collar: dt_util.utc_from_timestamp(collar.last_report_date),
840846
),
847+
# grid_state does not seem to change when off-grid, but rather admin_state_str
841848
EnvoyCollarSensorEntityDescription(
842849
key="grid_state",
843850
translation_key="grid_status",
844851
value_fn=lambda collar: collar.grid_state,
845852
),
853+
# grid_status off-grid shows in admin_state rather than in grid_state
854+
# map values as translations don't accept uppercase which these are
855+
EnvoyCollarSensorEntityDescription(
856+
key="admin_state_str",
857+
translation_key="admin_state",
858+
value_fn=lambda collar: ADMIN_STATE_MAP.get(
859+
collar.admin_state_str, collar.admin_state_str
860+
),
861+
),
846862
EnvoyCollarSensorEntityDescription(
847863
key="mid_state",
848864
translation_key="mid_state",

homeassistant/components/enphase_envoy/strings.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,26 @@
409409
"name": "Last report duration"
410410
},
411411
"grid_status": {
412-
"name": "[%key:component::enphase_envoy::entity::binary_sensor::grid_status::name%]"
412+
"name": "[%key:component::enphase_envoy::entity::binary_sensor::grid_status::name%]",
413+
"state": {
414+
"on_grid": "On grid",
415+
"off_grid": "Off grid",
416+
"synchronizing": "Synchronizing to grid"
417+
}
413418
},
414419
"mid_state": {
415-
"name": "MID state"
420+
"name": "MID state",
421+
"state": {
422+
"open": "[%key:common::state::open%]",
423+
"close": "[%key:common::state::closed%]"
424+
}
425+
},
426+
"admin_state": {
427+
"name": "Admin state",
428+
"state": {
429+
"on_grid": "[%key:component::enphase_envoy::entity::sensor::grid_status::state::on_grid%]",
430+
"off_grid": "[%key:component::enphase_envoy::entity::sensor::grid_status::state::off_grid%]"
431+
}
416432
}
417433
},
418434
"switch": {

tests/components/enphase_envoy/snapshots/test_sensor.ambr

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13996,6 +13996,54 @@
1399613996
'state': '2025-07-19T17:17:31+00:00',
1399713997
})
1399813998
# ---
13999+
# name: test_sensor[envoy_metered_batt_relay][sensor.collar_482520020939_admin_state-entry]
14000+
EntityRegistryEntrySnapshot({
14001+
'aliases': set({
14002+
}),
14003+
'area_id': None,
14004+
'capabilities': None,
14005+
'config_entry_id': <ANY>,
14006+
'config_subentry_id': <ANY>,
14007+
'device_class': None,
14008+
'device_id': <ANY>,
14009+
'disabled_by': None,
14010+
'domain': 'sensor',
14011+
'entity_category': None,
14012+
'entity_id': 'sensor.collar_482520020939_admin_state',
14013+
'has_entity_name': True,
14014+
'hidden_by': None,
14015+
'icon': None,
14016+
'id': <ANY>,
14017+
'labels': set({
14018+
}),
14019+
'name': None,
14020+
'options': dict({
14021+
}),
14022+
'original_device_class': None,
14023+
'original_icon': None,
14024+
'original_name': 'Admin state',
14025+
'platform': 'enphase_envoy',
14026+
'previous_unique_id': None,
14027+
'suggested_object_id': None,
14028+
'supported_features': 0,
14029+
'translation_key': 'admin_state',
14030+
'unique_id': '482520020939_admin_state_str',
14031+
'unit_of_measurement': None,
14032+
})
14033+
# ---
14034+
# name: test_sensor[envoy_metered_batt_relay][sensor.collar_482520020939_admin_state-state]
14035+
StateSnapshot({
14036+
'attributes': ReadOnlyDict({
14037+
'friendly_name': 'Collar 482520020939 Admin state',
14038+
}),
14039+
'context': <ANY>,
14040+
'entity_id': 'sensor.collar_482520020939_admin_state',
14041+
'last_changed': <ANY>,
14042+
'last_reported': <ANY>,
14043+
'last_updated': <ANY>,
14044+
'state': 'on_grid',
14045+
})
14046+
# ---
1399914047
# name: test_sensor[envoy_metered_batt_relay][sensor.collar_482520020939_grid_status-entry]
1400014048
EntityRegistryEntrySnapshot({
1400114049
'aliases': set({

0 commit comments

Comments
 (0)