From dea29f539f317a97e6a5f2f16131fb64884dc801 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Wed, 15 Mar 2023 18:52:42 +0100 Subject: [PATCH] Use `SensorDeviceClass.ENUM` and add state attributes translations in Shelly integration (#89660) --- .../components/shelly/binary_sensor.py | 1 + homeassistant/components/shelly/sensor.py | 3 ++ homeassistant/components/shelly/strings.json | 37 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/homeassistant/components/shelly/binary_sensor.py b/homeassistant/components/shelly/binary_sensor.py index 820afcf0f09..449fc142218 100644 --- a/homeassistant/components/shelly/binary_sensor.py +++ b/homeassistant/components/shelly/binary_sensor.py @@ -91,6 +91,7 @@ SENSORS: Final = { key="sensor|gas", name="Gas", device_class=BinarySensorDeviceClass.GAS, + translation_key="gas", value=lambda value: value in ["mild", "heavy"], extra_state_attributes=lambda block: {"detected": block.gas}, ), diff --git a/homeassistant/components/shelly/sensor.py b/homeassistant/components/shelly/sensor.py index 5e05134fdc3..b83131a1004 100644 --- a/homeassistant/components/shelly/sensor.py +++ b/homeassistant/components/shelly/sensor.py @@ -295,6 +295,9 @@ SENSORS: Final = { ("sensor", "sensorOp"): BlockSensorDescription( key="sensor|sensorOp", name="Operation", + device_class=SensorDeviceClass.ENUM, + options=["unknown", "warmup", "normal", "fault"], + translation_key="operation", icon="mdi:cog-transfer", value=lambda value: value, extra_state_attributes=lambda block: {"self_test": block.selfTest}, diff --git a/homeassistant/components/shelly/strings.json b/homeassistant/components/shelly/strings.json index 62a43c5bbc0..f0d4e1c9bd9 100644 --- a/homeassistant/components/shelly/strings.json +++ b/homeassistant/components/shelly/strings.json @@ -81,5 +81,42 @@ "passive": "Passive" } } + }, + "entity": { + "binary_sensor": { + "gas": { + "state_attributes": { + "detected": { + "state": { + "unknown": "Unknown", + "none": "None", + "mild": "Mild", + "heavy": "Heavy", + "test": "Test" + } + } + } + } + }, + "sensor": { + "operation": { + "state": { + "unknown": "Unknown", + "warmup": "Warm-up", + "normal": "normal", + "fault": "Fault" + }, + "state_attributes": { + "self_test": { + "state": { + "not_completed": "Not completed", + "completed": "Completed", + "running": "Running", + "pending": "Pending" + } + } + } + } + } } }