Add device class ENUM and options for sensors in NUT (#142242)

Add device class ENUM and options for sensors
This commit is contained in:
tdfountain 2025-04-04 00:48:39 -07:00 committed by GitHub
parent b5721604b9
commit 9ed8419b5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 66 additions and 7 deletions

View File

@ -40,13 +40,31 @@ AMBIENT_SENSORS = {
"ambient.temperature",
"ambient.temperature.status",
}
AMBIENT_THRESHOLD_STATUS_OPTIONS = [
BATTERY_CHARGER_STATUS_OPTIONS = [
"charging",
"discharging",
"floating",
"resting",
"unknown",
"disabled",
"off",
]
FREQUENCY_STATUS_OPTIONS = [
"good",
"out-of-range",
]
THRESHOLD_STATUS_OPTIONS = [
"good",
"warning-low",
"critical-low",
"warning-high",
"critical-high",
]
UPS_BEEPER_STATUS_OPTIONS = [
"enabled",
"disabled",
"muted",
]
_LOGGER = logging.getLogger(__name__)
@ -64,7 +82,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
key="ambient.humidity.status",
translation_key="ambient_humidity_status",
device_class=SensorDeviceClass.ENUM,
options=AMBIENT_THRESHOLD_STATUS_OPTIONS,
options=THRESHOLD_STATUS_OPTIONS,
entity_category=EntityCategory.DIAGNOSTIC,
),
"ambient.temperature": SensorEntityDescription(
@ -79,7 +97,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
key="ambient.temperature.status",
translation_key="ambient_temperature_status",
device_class=SensorDeviceClass.ENUM,
options=AMBIENT_THRESHOLD_STATUS_OPTIONS,
options=THRESHOLD_STATUS_OPTIONS,
entity_category=EntityCategory.DIAGNOSTIC,
),
"battery.alarm.threshold": SensorEntityDescription(
@ -126,6 +144,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.charger.status": SensorEntityDescription(
key="battery.charger.status",
translation_key="battery_charger_status",
device_class=SensorDeviceClass.ENUM,
options=BATTERY_CHARGER_STATUS_OPTIONS,
),
"battery.current": SensorEntityDescription(
key="battery.current",
@ -374,6 +394,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.current.status": SensorEntityDescription(
key="input.current.status",
translation_key="input_current_status",
device_class=SensorDeviceClass.ENUM,
options=THRESHOLD_STATUS_OPTIONS,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
@ -397,6 +419,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.frequency.status": SensorEntityDescription(
key="input.frequency.status",
translation_key="input_frequency_status",
device_class=SensorDeviceClass.ENUM,
options=FREQUENCY_STATUS_OPTIONS,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
@ -792,6 +816,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.beeper.status": SensorEntityDescription(
key="ups.beeper.status",
translation_key="ups_beeper_status",
device_class=SensorDeviceClass.ENUM,
options=UPS_BEEPER_STATUS_OPTIONS,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),

View File

@ -104,7 +104,18 @@
"battery_charge_low": { "name": "Low battery setpoint" },
"battery_charge_restart": { "name": "Minimum battery to start" },
"battery_charge_warning": { "name": "Warning battery setpoint" },
"battery_charger_status": { "name": "Charging status" },
"battery_charger_status": {
"name": "Charging status",
"state": {
"charging": "Charging",
"discharging": "Discharging",
"floating": "Floating",
"resting": "Resting",
"unknown": "Unknown",
"disabled": "Disabled",
"off": "Off"
}
},
"battery_current": { "name": "Battery current" },
"battery_current_total": { "name": "Total battery current" },
"battery_date": { "name": "Battery date" },
@ -135,10 +146,25 @@
"input_bypass_realpower": { "name": "Input bypass real power" },
"input_bypass_voltage": { "name": "Input bypass voltage" },
"input_current": { "name": "Input current" },
"input_current_status": { "name": "Input current status" },
"input_current_status": {
"name": "Input current status",
"state": {
"good": "[%key:component::nut::entity::sensor::ambient_humidity_status::state::good%]",
"warning-low": "[%key:component::nut::entity::sensor::ambient_humidity_status::state::warning-low%]",
"critical-low": "[%key:component::nut::entity::sensor::ambient_humidity_status::state::critical-low%]",
"warning-high": "[%key:component::nut::entity::sensor::ambient_humidity_status::state::warning-high%]",
"critical-high": "[%key:component::nut::entity::sensor::ambient_humidity_status::state::critical-high%]"
}
},
"input_frequency": { "name": "Input frequency" },
"input_frequency_nominal": { "name": "Input nominal frequency" },
"input_frequency_status": { "name": "Input frequency status" },
"input_frequency_status": {
"name": "Input frequency status",
"state": {
"good": "Good",
"out-of-range": "Out of range"
}
},
"input_l1_current": { "name": "Input L1 current" },
"input_l1_frequency": { "name": "Input L1 line frequency" },
"input_l1_n_voltage": { "name": "Input L1 voltage" },
@ -194,7 +220,14 @@
"output_voltage": { "name": "Output voltage" },
"output_voltage_nominal": { "name": "Nominal output voltage" },
"ups_alarm": { "name": "Alarms" },
"ups_beeper_status": { "name": "Beeper status" },
"ups_beeper_status": {
"name": "Beeper status",
"state": {
"enabled": "Enabled",
"disabled": "Disabled",
"muted": "Muted"
}
},
"ups_contacts": { "name": "External contacts" },
"ups_delay_reboot": { "name": "UPS reboot delay" },
"ups_delay_shutdown": { "name": "UPS shutdown delay" },