Use Color enum for status options

This commit is contained in:
Parker Brown 2025-02-06 02:48:41 +00:00 committed by GitHub
parent aee85a80b4
commit 73226ba138
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,7 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any from typing import Any
from aranet4.client import Aranet4Advertisement from aranet4.client import Aranet4Advertisement, Color
from bleak.backends.device import BLEDevice from bleak.backends.device import BLEDevice
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
@ -78,7 +78,7 @@ SENSOR_DESCRIPTIONS = {
key="status", key="status",
name="Threshold Level", name="Threshold Level",
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
options=["green", "yellow", "red"], options=[status.name for status in Color],
), ),
"co2": AranetSensorEntityDescription( "co2": AranetSensorEntityDescription(
key="co2", key="co2",
@ -167,7 +167,10 @@ def sensor_update_to_bluetooth_data_update(
val = getattr(adv.readings, key) val = getattr(adv.readings, key)
if val == -1: if val == -1:
continue continue
val *= desc.scale if key == "status":
val = val.name # Use the name of the status
else:
val *= desc.scale
data[tag] = val data[tag] = val
names[tag] = desc.name names[tag] = desc.name
descs[tag] = desc descs[tag] = desc