Add state translations for OpenUV UV Level sensor (#101978)

This commit is contained in:
Aaron Bach 2023-10-14 10:31:46 -06:00 committed by GitHub
parent 76083a0b4c
commit 2d1afc1c7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -6,6 +6,7 @@ from dataclasses import dataclass
from typing import Any from typing import Any
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass, SensorStateClass,
@ -54,11 +55,11 @@ class UvLabel:
UV_LABEL_DEFINITIONS = ( UV_LABEL_DEFINITIONS = (
UvLabel(value="Extreme", minimum_index=11), UvLabel(value="extreme", minimum_index=11),
UvLabel(value="Very High", minimum_index=8), UvLabel(value="very_high", minimum_index=8),
UvLabel(value="High", minimum_index=6), UvLabel(value="high", minimum_index=6),
UvLabel(value="Moderate", minimum_index=3), UvLabel(value="moderate", minimum_index=3),
UvLabel(value="Low", minimum_index=0), UvLabel(value="low", minimum_index=0),
) )
@ -104,6 +105,8 @@ SENSOR_DESCRIPTIONS = (
key=TYPE_CURRENT_UV_LEVEL, key=TYPE_CURRENT_UV_LEVEL,
translation_key="current_uv_level", translation_key="current_uv_level",
icon="mdi:weather-sunny", icon="mdi:weather-sunny",
device_class=SensorDeviceClass.ENUM,
options=[label.value for label in UV_LABEL_DEFINITIONS],
value_fn=lambda data: get_uv_label(data["uv"]), value_fn=lambda data: get_uv_label(data["uv"]),
), ),
OpenUvSensorEntityDescription( OpenUvSensorEntityDescription(

View File

@ -51,7 +51,14 @@
"name": "Current UV index" "name": "Current UV index"
}, },
"current_uv_level": { "current_uv_level": {
"name": "Current UV level" "name": "Current UV level",
"state": {
"extreme": "Extreme",
"high": "High",
"low": "Low",
"moderate": "Moderate",
"very_high": "Very high"
}
}, },
"max_uv_index": { "max_uv_index": {
"name": "Max UV index" "name": "Max UV index"