mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Migrate APCUPSD to has entity name (#112997)
* Properly set entity names for APCUPSD * Add test cases to prevent future regressions * Fix tests due to the updated entity IDs * Prettify code * Remove redundant translation key
This commit is contained in:
@@ -34,11 +34,10 @@ SENSORS: dict[str, SensorEntityDescription] = {
|
||||
"alarmdel": SensorEntityDescription(
|
||||
key="alarmdel",
|
||||
translation_key="alarm_delay",
|
||||
name="UPS Alarm Delay",
|
||||
),
|
||||
"ambtemp": SensorEntityDescription(
|
||||
key="ambtemp",
|
||||
name="UPS Ambient Temperature",
|
||||
translation_key="ambient_temperature",
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
@@ -46,40 +45,34 @@ SENSORS: dict[str, SensorEntityDescription] = {
|
||||
"apc": SensorEntityDescription(
|
||||
key="apc",
|
||||
translation_key="apc_status",
|
||||
name="UPS Status Data",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"apcmodel": SensorEntityDescription(
|
||||
key="apcmodel",
|
||||
translation_key="apc_model",
|
||||
name="UPS Model",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"badbatts": SensorEntityDescription(
|
||||
key="badbatts",
|
||||
translation_key="bad_batteries",
|
||||
name="UPS Bad Batteries",
|
||||
),
|
||||
"battdate": SensorEntityDescription(
|
||||
key="battdate",
|
||||
translation_key="battery_replacement_date",
|
||||
name="UPS Battery Replaced",
|
||||
),
|
||||
"battstat": SensorEntityDescription(
|
||||
key="battstat",
|
||||
translation_key="battery_status",
|
||||
name="UPS Battery Status",
|
||||
),
|
||||
"battv": SensorEntityDescription(
|
||||
key="battv",
|
||||
name="UPS Battery Voltage",
|
||||
translation_key="battery_voltage",
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"bcharge": SensorEntityDescription(
|
||||
key="bcharge",
|
||||
name="UPS Battery",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
device_class=SensorDeviceClass.BATTERY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
@@ -87,86 +80,74 @@ SENSORS: dict[str, SensorEntityDescription] = {
|
||||
"cable": SensorEntityDescription(
|
||||
key="cable",
|
||||
translation_key="cable_type",
|
||||
name="UPS Cable Type",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"cumonbatt": SensorEntityDescription(
|
||||
key="cumonbatt",
|
||||
translation_key="total_time_on_battery",
|
||||
name="UPS Total Time on Battery",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
"date": SensorEntityDescription(
|
||||
key="date",
|
||||
translation_key="date",
|
||||
name="UPS Status Date",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"dipsw": SensorEntityDescription(
|
||||
key="dipsw",
|
||||
translation_key="dip_switch_settings",
|
||||
name="UPS Dip Switch Settings",
|
||||
),
|
||||
"dlowbatt": SensorEntityDescription(
|
||||
key="dlowbatt",
|
||||
translation_key="low_battery_signal",
|
||||
name="UPS Low Battery Signal",
|
||||
),
|
||||
"driver": SensorEntityDescription(
|
||||
key="driver",
|
||||
translation_key="driver",
|
||||
name="UPS Driver",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"dshutd": SensorEntityDescription(
|
||||
key="dshutd",
|
||||
translation_key="shutdown_delay",
|
||||
name="UPS Shutdown Delay",
|
||||
),
|
||||
"dwake": SensorEntityDescription(
|
||||
key="dwake",
|
||||
translation_key="wake_delay",
|
||||
name="UPS Wake Delay",
|
||||
),
|
||||
"end apc": SensorEntityDescription(
|
||||
key="end apc",
|
||||
translation_key="date_and_time",
|
||||
name="UPS Date and Time",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"extbatts": SensorEntityDescription(
|
||||
key="extbatts",
|
||||
translation_key="external_batteries",
|
||||
name="UPS External Batteries",
|
||||
),
|
||||
"firmware": SensorEntityDescription(
|
||||
key="firmware",
|
||||
translation_key="firmware_version",
|
||||
name="UPS Firmware Version",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"hitrans": SensorEntityDescription(
|
||||
key="hitrans",
|
||||
name="UPS Transfer High",
|
||||
translation_key="transfer_high",
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
),
|
||||
"hostname": SensorEntityDescription(
|
||||
key="hostname",
|
||||
translation_key="hostname",
|
||||
name="UPS Hostname",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"humidity": SensorEntityDescription(
|
||||
key="humidity",
|
||||
name="UPS Ambient Humidity",
|
||||
translation_key="humidity",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"itemp": SensorEntityDescription(
|
||||
key="itemp",
|
||||
name="UPS Internal Temperature",
|
||||
translation_key="internal_temperature",
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
@@ -174,29 +155,26 @@ SENSORS: dict[str, SensorEntityDescription] = {
|
||||
"laststest": SensorEntityDescription(
|
||||
key="laststest",
|
||||
translation_key="last_self_test",
|
||||
name="UPS Last Self Test",
|
||||
),
|
||||
"lastxfer": SensorEntityDescription(
|
||||
key="lastxfer",
|
||||
translation_key="last_transfer",
|
||||
name="UPS Last Transfer",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"linefail": SensorEntityDescription(
|
||||
key="linefail",
|
||||
translation_key="line_failure",
|
||||
name="UPS Input Voltage Status",
|
||||
),
|
||||
"linefreq": SensorEntityDescription(
|
||||
key="linefreq",
|
||||
name="UPS Line Frequency",
|
||||
translation_key="line_frequency",
|
||||
native_unit_of_measurement=UnitOfFrequency.HERTZ,
|
||||
device_class=SensorDeviceClass.FREQUENCY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"linev": SensorEntityDescription(
|
||||
key="linev",
|
||||
name="UPS Input Voltage",
|
||||
translation_key="line_voltage",
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
@@ -204,113 +182,104 @@ SENSORS: dict[str, SensorEntityDescription] = {
|
||||
"loadpct": SensorEntityDescription(
|
||||
key="loadpct",
|
||||
translation_key="load_capacity",
|
||||
name="UPS Load",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"loadapnt": SensorEntityDescription(
|
||||
key="loadapnt",
|
||||
translation_key="apparent_power",
|
||||
name="UPS Load Apparent Power",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
"lotrans": SensorEntityDescription(
|
||||
key="lotrans",
|
||||
name="UPS Transfer Low",
|
||||
translation_key="transfer_low",
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
),
|
||||
"mandate": SensorEntityDescription(
|
||||
key="mandate",
|
||||
translation_key="manufacture_date",
|
||||
name="UPS Manufacture Date",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"masterupd": SensorEntityDescription(
|
||||
key="masterupd",
|
||||
translation_key="master_update",
|
||||
name="UPS Master Update",
|
||||
),
|
||||
"maxlinev": SensorEntityDescription(
|
||||
key="maxlinev",
|
||||
name="UPS Input Voltage High",
|
||||
translation_key="input_voltage_high",
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
),
|
||||
"maxtime": SensorEntityDescription(
|
||||
key="maxtime",
|
||||
translation_key="max_time",
|
||||
name="UPS Battery Timeout",
|
||||
),
|
||||
"mbattchg": SensorEntityDescription(
|
||||
key="mbattchg",
|
||||
translation_key="max_battery_charge",
|
||||
name="UPS Battery Shutdown",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
"minlinev": SensorEntityDescription(
|
||||
key="minlinev",
|
||||
name="UPS Input Voltage Low",
|
||||
translation_key="input_voltage_low",
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
),
|
||||
"mintimel": SensorEntityDescription(
|
||||
key="mintimel",
|
||||
translation_key="min_time",
|
||||
name="UPS Shutdown Time",
|
||||
),
|
||||
"model": SensorEntityDescription(
|
||||
key="model",
|
||||
translation_key="model",
|
||||
name="UPS Model",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"nombattv": SensorEntityDescription(
|
||||
key="nombattv",
|
||||
name="UPS Battery Nominal Voltage",
|
||||
translation_key="battery_nominal_voltage",
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
),
|
||||
"nominv": SensorEntityDescription(
|
||||
key="nominv",
|
||||
name="UPS Nominal Input Voltage",
|
||||
translation_key="nominal_input_voltage",
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
),
|
||||
"nomoutv": SensorEntityDescription(
|
||||
key="nomoutv",
|
||||
name="UPS Nominal Output Voltage",
|
||||
translation_key="nominal_output_voltage",
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
),
|
||||
"nompower": SensorEntityDescription(
|
||||
key="nompower",
|
||||
name="UPS Nominal Output Power",
|
||||
translation_key="nominal_output_power",
|
||||
native_unit_of_measurement=UnitOfPower.WATT,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
),
|
||||
"nomapnt": SensorEntityDescription(
|
||||
key="nomapnt",
|
||||
name="UPS Nominal Apparent Power",
|
||||
translation_key="nominal_apparent_power",
|
||||
native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
|
||||
device_class=SensorDeviceClass.APPARENT_POWER,
|
||||
),
|
||||
"numxfers": SensorEntityDescription(
|
||||
key="numxfers",
|
||||
translation_key="transfer_count",
|
||||
name="UPS Transfer Count",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
"outcurnt": SensorEntityDescription(
|
||||
key="outcurnt",
|
||||
name="UPS Output Current",
|
||||
translation_key="output_current",
|
||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||
device_class=SensorDeviceClass.CURRENT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"outputv": SensorEntityDescription(
|
||||
key="outputv",
|
||||
name="UPS Output Voltage",
|
||||
translation_key="output_voltage",
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
@@ -318,108 +287,89 @@ SENSORS: dict[str, SensorEntityDescription] = {
|
||||
"reg1": SensorEntityDescription(
|
||||
key="reg1",
|
||||
translation_key="register_1_fault",
|
||||
name="UPS Register 1 Fault",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"reg2": SensorEntityDescription(
|
||||
key="reg2",
|
||||
translation_key="register_2_fault",
|
||||
name="UPS Register 2 Fault",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"reg3": SensorEntityDescription(
|
||||
key="reg3",
|
||||
translation_key="register_3_fault",
|
||||
name="UPS Register 3 Fault",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"retpct": SensorEntityDescription(
|
||||
key="retpct",
|
||||
translation_key="restore_capacity",
|
||||
name="UPS Restore Requirement",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
"selftest": SensorEntityDescription(
|
||||
key="selftest",
|
||||
translation_key="self_test_result",
|
||||
name="UPS Self Test result",
|
||||
),
|
||||
"sense": SensorEntityDescription(
|
||||
key="sense",
|
||||
translation_key="sensitivity",
|
||||
name="UPS Sensitivity",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"serialno": SensorEntityDescription(
|
||||
key="serialno",
|
||||
translation_key="serial_number",
|
||||
name="UPS Serial Number",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"starttime": SensorEntityDescription(
|
||||
key="starttime",
|
||||
translation_key="startup_time",
|
||||
name="UPS Startup Time",
|
||||
),
|
||||
"statflag": SensorEntityDescription(
|
||||
key="statflag",
|
||||
translation_key="online_status",
|
||||
name="UPS Status Flag",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"status": SensorEntityDescription(
|
||||
key="status",
|
||||
translation_key="status",
|
||||
name="UPS Status",
|
||||
),
|
||||
"stesti": SensorEntityDescription(
|
||||
key="stesti",
|
||||
translation_key="self_test_interval",
|
||||
name="UPS Self Test Interval",
|
||||
),
|
||||
"timeleft": SensorEntityDescription(
|
||||
key="timeleft",
|
||||
translation_key="time_left",
|
||||
name="UPS Time Left",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"tonbatt": SensorEntityDescription(
|
||||
key="tonbatt",
|
||||
translation_key="time_on_battery",
|
||||
name="UPS Time on Battery",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
"upsmode": SensorEntityDescription(
|
||||
key="upsmode",
|
||||
translation_key="ups_mode",
|
||||
name="UPS Mode",
|
||||
),
|
||||
"upsname": SensorEntityDescription(
|
||||
key="upsname",
|
||||
translation_key="ups_name",
|
||||
name="UPS Name",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"version": SensorEntityDescription(
|
||||
key="version",
|
||||
translation_key="version",
|
||||
name="UPS Daemon Info",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"xoffbat": SensorEntityDescription(
|
||||
key="xoffbat",
|
||||
translation_key="transfer_from_battery",
|
||||
name="UPS Transfer from Battery",
|
||||
),
|
||||
"xoffbatt": SensorEntityDescription(
|
||||
key="xoffbatt",
|
||||
translation_key="transfer_from_battery",
|
||||
name="UPS Transfer from Battery",
|
||||
),
|
||||
"xonbatt": SensorEntityDescription(
|
||||
key="xonbatt",
|
||||
translation_key="transfer_to_battery",
|
||||
name="UPS Transfer to Battery",
|
||||
),
|
||||
}
|
||||
|
||||
@@ -486,6 +436,8 @@ def infer_unit(value: str) -> tuple[str, str | None]:
|
||||
class APCUPSdSensor(CoordinatorEntity[APCUPSdCoordinator], SensorEntity):
|
||||
"""Representation of a sensor entity for APCUPSd status values."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: APCUPSdCoordinator,
|
||||
|
||||
Reference in New Issue
Block a user