Skip to content

Commit 25d44e8

Browse files
authored
Enhance compressor phase with state translations in ViCare integration (home-assistant#156238)
1 parent 0a480a2 commit 25d44e8

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

homeassistant/components/vicare/sensor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
get_compressors,
5959
get_device_serial,
6060
is_supported,
61+
normalize_state,
6162
)
6263

6364
_LOGGER = logging.getLogger(__name__)
@@ -1086,7 +1087,7 @@ class ViCareSensorEntityDescription(SensorEntityDescription, ViCareRequiredKeysM
10861087
ViCareSensorEntityDescription(
10871088
key="compressor_phase",
10881089
translation_key="compressor_phase",
1089-
value_getter=lambda api: api.getPhase(),
1090+
value_getter=lambda api: normalize_state(api.getPhase()),
10901091
entity_category=EntityCategory.DIAGNOSTIC,
10911092
),
10921093
)

homeassistant/components/vicare/strings.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,18 @@
213213
"name": "Compressor hours load class 5"
214214
},
215215
"compressor_phase": {
216-
"name": "Compressor phase"
216+
"name": "Compressor phase",
217+
"state": {
218+
"cooling": "[%key:component::climate::entity_component::_::state_attributes::hvac_action::state::cooling%]",
219+
"defrost": "[%key:component::climate::entity_component::_::state_attributes::hvac_action::state::defrosting%]",
220+
"heating": "[%key:component::climate::entity_component::_::state_attributes::hvac_action::state::heating%]",
221+
"off": "[%key:common::state::off%]",
222+
"passive_defrost": "Passive defrosting",
223+
"pause": "[%key:common::state::idle%]",
224+
"preparing": "Preparing",
225+
"preparing_defrost": "Preparing defrost",
226+
"ready": "[%key:common::state::idle%]"
227+
}
217228
},
218229
"compressor_starts": {
219230
"name": "Compressor starts"

homeassistant/components/vicare/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,8 @@ def get_compressors(device: PyViCareDevice) -> list[PyViCareHeatingDeviceCompone
133133
def filter_state(state: str) -> str | None:
134134
"""Return the state if not 'nothing' or 'unknown'."""
135135
return None if state in ("nothing", "unknown") else state
136+
137+
138+
def normalize_state(state: str) -> str:
139+
"""Return the state with underscores instead of hyphens."""
140+
return state.replace("-", "_")

0 commit comments

Comments
 (0)