Fix attr_unit_of_measurement in update of apcupsd entity (#53947)

pull/54000/head
Michael 2021-08-04 21:24:19 +02:00 committed by GitHub
parent 3f6282eb7a
commit f7fb4ad782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 47 deletions

View File

@ -26,72 +26,72 @@ _LOGGER = logging.getLogger(__name__)
SENSOR_PREFIX = "UPS "
SENSOR_TYPES = {
"alarmdel": ["Alarm Delay", "", "mdi:alarm", None],
"ambtemp": ["Ambient Temperature", "", "mdi:thermometer", None],
"apc": ["Status Data", "", "mdi:information-outline", None],
"apcmodel": ["Model", "", "mdi:information-outline", None],
"badbatts": ["Bad Batteries", "", "mdi:information-outline", None],
"battdate": ["Battery Replaced", "", "mdi:calendar-clock", None],
"battstat": ["Battery Status", "", "mdi:information-outline", None],
"alarmdel": ["Alarm Delay", None, "mdi:alarm", None],
"ambtemp": ["Ambient Temperature", None, "mdi:thermometer", None],
"apc": ["Status Data", None, "mdi:information-outline", None],
"apcmodel": ["Model", None, "mdi:information-outline", None],
"badbatts": ["Bad Batteries", None, "mdi:information-outline", None],
"battdate": ["Battery Replaced", None, "mdi:calendar-clock", None],
"battstat": ["Battery Status", None, "mdi:information-outline", None],
"battv": ["Battery Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash", None],
"bcharge": ["Battery", PERCENTAGE, "mdi:battery", None],
"cable": ["Cable Type", "", "mdi:ethernet-cable", None],
"cumonbatt": ["Total Time on Battery", "", "mdi:timer-outline", None],
"date": ["Status Date", "", "mdi:calendar-clock", None],
"dipsw": ["Dip Switch Settings", "", "mdi:information-outline", None],
"dlowbatt": ["Low Battery Signal", "", "mdi:clock-alert", None],
"driver": ["Driver", "", "mdi:information-outline", None],
"dshutd": ["Shutdown Delay", "", "mdi:timer-outline", None],
"dwake": ["Wake Delay", "", "mdi:timer-outline", None],
"endapc": ["Date and Time", "", "mdi:calendar-clock", None],
"extbatts": ["External Batteries", "", "mdi:information-outline", None],
"firmware": ["Firmware Version", "", "mdi:information-outline", None],
"cable": ["Cable Type", None, "mdi:ethernet-cable", None],
"cumonbatt": ["Total Time on Battery", None, "mdi:timer-outline", None],
"date": ["Status Date", None, "mdi:calendar-clock", None],
"dipsw": ["Dip Switch Settings", None, "mdi:information-outline", None],
"dlowbatt": ["Low Battery Signal", None, "mdi:clock-alert", None],
"driver": ["Driver", None, "mdi:information-outline", None],
"dshutd": ["Shutdown Delay", None, "mdi:timer-outline", None],
"dwake": ["Wake Delay", None, "mdi:timer-outline", None],
"endapc": ["Date and Time", None, "mdi:calendar-clock", None],
"extbatts": ["External Batteries", None, "mdi:information-outline", None],
"firmware": ["Firmware Version", None, "mdi:information-outline", None],
"hitrans": ["Transfer High", ELECTRIC_POTENTIAL_VOLT, "mdi:flash", None],
"hostname": ["Hostname", "", "mdi:information-outline", None],
"hostname": ["Hostname", None, "mdi:information-outline", None],
"humidity": ["Ambient Humidity", PERCENTAGE, "mdi:water-percent", None],
"itemp": ["Internal Temperature", TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE],
"lastxfer": ["Last Transfer", "", "mdi:transfer", None],
"linefail": ["Input Voltage Status", "", "mdi:information-outline", None],
"lastxfer": ["Last Transfer", None, "mdi:transfer", None],
"linefail": ["Input Voltage Status", None, "mdi:information-outline", None],
"linefreq": ["Line Frequency", FREQUENCY_HERTZ, "mdi:information-outline", None],
"linev": ["Input Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash", None],
"loadpct": ["Load", PERCENTAGE, "mdi:gauge", None],
"loadapnt": ["Load Apparent Power", PERCENTAGE, "mdi:gauge", None],
"lotrans": ["Transfer Low", ELECTRIC_POTENTIAL_VOLT, "mdi:flash", None],
"mandate": ["Manufacture Date", "", "mdi:calendar", None],
"masterupd": ["Master Update", "", "mdi:information-outline", None],
"mandate": ["Manufacture Date", None, "mdi:calendar", None],
"masterupd": ["Master Update", None, "mdi:information-outline", None],
"maxlinev": ["Input Voltage High", ELECTRIC_POTENTIAL_VOLT, "mdi:flash", None],
"maxtime": ["Battery Timeout", "", "mdi:timer-off-outline", None],
"maxtime": ["Battery Timeout", None, "mdi:timer-off-outline", None],
"mbattchg": ["Battery Shutdown", PERCENTAGE, "mdi:battery-alert", None],
"minlinev": ["Input Voltage Low", ELECTRIC_POTENTIAL_VOLT, "mdi:flash", None],
"mintimel": ["Shutdown Time", "", "mdi:timer-outline", None],
"model": ["Model", "", "mdi:information-outline", None],
"mintimel": ["Shutdown Time", None, "mdi:timer-outline", None],
"model": ["Model", None, "mdi:information-outline", None],
"nombattv": ["Battery Nominal Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash", None],
"nominv": ["Nominal Input Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash", None],
"nomoutv": ["Nominal Output Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash", None],
"nompower": ["Nominal Output Power", POWER_WATT, "mdi:flash", None],
"nomapnt": ["Nominal Apparent Power", POWER_VOLT_AMPERE, "mdi:flash", None],
"numxfers": ["Transfer Count", "", "mdi:counter", None],
"numxfers": ["Transfer Count", None, "mdi:counter", None],
"outcurnt": ["Output Current", ELECTRIC_CURRENT_AMPERE, "mdi:flash", None],
"outputv": ["Output Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash", None],
"reg1": ["Register 1 Fault", "", "mdi:information-outline", None],
"reg2": ["Register 2 Fault", "", "mdi:information-outline", None],
"reg3": ["Register 3 Fault", "", "mdi:information-outline", None],
"reg1": ["Register 1 Fault", None, "mdi:information-outline", None],
"reg2": ["Register 2 Fault", None, "mdi:information-outline", None],
"reg3": ["Register 3 Fault", None, "mdi:information-outline", None],
"retpct": ["Restore Requirement", PERCENTAGE, "mdi:battery-alert", None],
"selftest": ["Last Self Test", "", "mdi:calendar-clock", None],
"sense": ["Sensitivity", "", "mdi:information-outline", None],
"serialno": ["Serial Number", "", "mdi:information-outline", None],
"starttime": ["Startup Time", "", "mdi:calendar-clock", None],
"statflag": ["Status Flag", "", "mdi:information-outline", None],
"status": ["Status", "", "mdi:information-outline", None],
"stesti": ["Self Test Interval", "", "mdi:information-outline", None],
"timeleft": ["Time Left", "", "mdi:clock-alert", None],
"tonbatt": ["Time on Battery", "", "mdi:timer-outline", None],
"upsmode": ["Mode", "", "mdi:information-outline", None],
"upsname": ["Name", "", "mdi:information-outline", None],
"version": ["Daemon Info", "", "mdi:information-outline", None],
"xoffbat": ["Transfer from Battery", "", "mdi:transfer", None],
"xoffbatt": ["Transfer from Battery", "", "mdi:transfer", None],
"xonbatt": ["Transfer to Battery", "", "mdi:transfer", None],
"selftest": ["Last Self Test", None, "mdi:calendar-clock", None],
"sense": ["Sensitivity", None, "mdi:information-outline", None],
"serialno": ["Serial Number", None, "mdi:information-outline", None],
"starttime": ["Startup Time", None, "mdi:calendar-clock", None],
"statflag": ["Status Flag", None, "mdi:information-outline", None],
"status": ["Status", None, "mdi:information-outline", None],
"stesti": ["Self Test Interval", None, "mdi:information-outline", None],
"timeleft": ["Time Left", None, "mdi:clock-alert", None],
"tonbatt": ["Time on Battery", None, "mdi:timer-outline", None],
"upsmode": ["Mode", None, "mdi:information-outline", None],
"upsname": ["Name", None, "mdi:information-outline", None],
"version": ["Daemon Info", None, "mdi:information-outline", None],
"xoffbat": ["Transfer from Battery", None, "mdi:transfer", None],
"xoffbatt": ["Transfer from Battery", None, "mdi:transfer", None],
"xonbatt": ["Transfer to Battery", None, "mdi:transfer", None],
}
SPECIFIC_UNITS = {"ITEMP": TEMP_CELSIUS}
@ -165,8 +165,7 @@ class APCUPSdSensor(SensorEntity):
self.type = sensor_type
self._attr_name = SENSOR_PREFIX + SENSOR_TYPES[sensor_type][0]
self._attr_icon = SENSOR_TYPES[self.type][2]
if SENSOR_TYPES[sensor_type][1]:
self._attr_unit_of_measurement = SENSOR_TYPES[sensor_type][1]
self._attr_unit_of_measurement = SENSOR_TYPES[sensor_type][1]
self._attr_device_class = SENSOR_TYPES[sensor_type][3]
def update(self):