From c25ba19ffdf2812c51be2a06c5178e3dad3552f8 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 6 Dec 2022 11:08:05 +0100 Subject: [PATCH] Use enum sensor device class in Litter-Robot (#83290) --- .../components/litterrobot/sensor.py | 30 ++++++++++++++++- .../components/litterrobot/strings.json | 33 +++++++++++++++++++ .../litterrobot/strings.sensor.json | 31 ----------------- .../litterrobot/translations/en.json | 33 +++++++++++++++++++ tests/components/litterrobot/test_sensor.py | 2 +- 5 files changed, 96 insertions(+), 33 deletions(-) delete mode 100644 homeassistant/components/litterrobot/strings.sensor.json diff --git a/homeassistant/components/litterrobot/sensor.py b/homeassistant/components/litterrobot/sensor.py index a65781db358..ab87df88bbe 100644 --- a/homeassistant/components/litterrobot/sensor.py +++ b/homeassistant/components/litterrobot/sensor.py @@ -97,8 +97,36 @@ ROBOT_SENSOR_MAP: dict[type[Robot], list[RobotSensorEntityDescription]] = { RobotSensorEntityDescription[LitterRobot]( key="status_code", name="Status Code", - device_class="litterrobot__status_code", + translation_key="status_code", entity_category=EntityCategory.DIAGNOSTIC, + device_class=SensorDeviceClass.ENUM, + options=[ + "br", + "ccc", + "ccp", + "cd", + "csf", + "csi", + "cst", + "df1", + "df2", + "dfs", + "dhf", + "dpf", + "ec", + "hpf", + "off", + "offline", + "otf", + "p", + "pd", + "pwrd", + "pwru", + "rdy", + "scf", + "sdf", + "spf", + ], ), ], LitterRobot4: [ diff --git a/homeassistant/components/litterrobot/strings.json b/homeassistant/components/litterrobot/strings.json index f2256249b8e..2d40eb6a044 100644 --- a/homeassistant/components/litterrobot/strings.json +++ b/homeassistant/components/litterrobot/strings.json @@ -30,5 +30,38 @@ "title": "Litter-Robot attributes are now their own sensors", "description": "The vacuum entity attributes are now available as diagnostic sensors.\n\nPlease adjust any automations or scripts you may have that use these attributes." } + }, + "entity": { + "sensor": { + "status_code": { + "state": { + "br": "Bonnet Removed", + "ccc": "Clean Cycle Complete", + "ccp": "Clean Cycle In Progress", + "cd": "Cat Detected", + "csf": "Cat Sensor Fault", + "csi": "Cat Sensor Interrupted", + "cst": "Cat Sensor Timing", + "df1": "Drawer Almost Full - 2 Cycles Left", + "df2": "Drawer Almost Full - 1 Cycle Left", + "dfs": "Drawer Full", + "dhf": "Dump + Home Position Fault", + "dpf": "Dump Position Fault", + "ec": "Empty Cycle", + "hpf": "Home Position Fault", + "off": "[%key:common::state::off%]", + "offline": "Offline", + "otf": "Over Torque Fault", + "p": "[%key:common::state::paused%]", + "pd": "Pinch Detect", + "pwrd": "Powering Down", + "pwru": "Powering Up", + "rdy": "Ready", + "scf": "Cat Sensor Fault At Startup", + "sdf": "Drawer Full At Startup", + "spf": "Pinch Detect At Startup" + } + } + } } } diff --git a/homeassistant/components/litterrobot/strings.sensor.json b/homeassistant/components/litterrobot/strings.sensor.json deleted file mode 100644 index 0c901704b02..00000000000 --- a/homeassistant/components/litterrobot/strings.sensor.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "state": { - "litterrobot__status_code": { - "br": "Bonnet Removed", - "ccc": "Clean Cycle Complete", - "ccp": "Clean Cycle In Progress", - "cd": "Cat Detected", - "csf": "Cat Sensor Fault", - "csi": "Cat Sensor Interrupted", - "cst": "Cat Sensor Timing", - "df1": "Drawer Almost Full - 2 Cycles Left", - "df2": "Drawer Almost Full - 1 Cycle Left", - "dfs": "Drawer Full", - "dhf": "Dump + Home Position Fault", - "dpf": "Dump Position Fault", - "ec": "Empty Cycle", - "hpf": "Home Position Fault", - "off": "[%key:common::state::off%]", - "offline": "Offline", - "otf": "Over Torque Fault", - "p": "[%key:common::state::paused%]", - "pd": "Pinch Detect", - "pwrd": "Powering Down", - "pwru": "Powering Up", - "rdy": "Ready", - "scf": "Cat Sensor Fault At Startup", - "sdf": "Drawer Full At Startup", - "spf": "Pinch Detect At Startup" - } - } -} diff --git a/homeassistant/components/litterrobot/translations/en.json b/homeassistant/components/litterrobot/translations/en.json index 76c0dcb79c9..c4010c63ecd 100644 --- a/homeassistant/components/litterrobot/translations/en.json +++ b/homeassistant/components/litterrobot/translations/en.json @@ -25,6 +25,39 @@ } } }, + "entity": { + "sensor": { + "status_code": { + "state": { + "br": "Bonnet Removed", + "ccc": "Clean Cycle Complete", + "ccp": "Clean Cycle In Progress", + "cd": "Cat Detected", + "csf": "Cat Sensor Fault", + "csi": "Cat Sensor Interrupted", + "cst": "Cat Sensor Timing", + "df1": "Drawer Almost Full - 2 Cycles Left", + "df2": "Drawer Almost Full - 1 Cycle Left", + "dfs": "Drawer Full", + "dhf": "Dump + Home Position Fault", + "dpf": "Dump Position Fault", + "ec": "Empty Cycle", + "hpf": "Home Position Fault", + "off": "Off", + "offline": "Offline", + "otf": "Over Torque Fault", + "p": "Paused", + "pd": "Pinch Detect", + "pwrd": "Powering Down", + "pwru": "Powering Up", + "rdy": "Ready", + "scf": "Cat Sensor Fault At Startup", + "sdf": "Drawer Full At Startup", + "spf": "Pinch Detect At Startup" + } + } + } + }, "issues": { "migrated_attributes": { "description": "The vacuum entity attributes are now available as diagnostic sensors.\n\nPlease adjust any automations or scripts you may have that use these attributes.", diff --git a/tests/components/litterrobot/test_sensor.py b/tests/components/litterrobot/test_sensor.py index 536e6ddf188..beed13c75dd 100644 --- a/tests/components/litterrobot/test_sensor.py +++ b/tests/components/litterrobot/test_sensor.py @@ -86,7 +86,7 @@ async def test_litter_robot_sensor( assert sensor.attributes["device_class"] == SensorDeviceClass.TIMESTAMP sensor = hass.states.get("sensor.test_status_code") assert sensor.state == "dfs" - assert sensor.attributes["device_class"] == "litterrobot__status_code" + assert sensor.attributes["device_class"] == SensorDeviceClass.ENUM sensor = hass.states.get("sensor.test_litter_level") assert sensor.state == "70.0" assert sensor.attributes["unit_of_measurement"] == PERCENTAGE