Use SensorEntityDescription and set state class measurement for NUT sensors (#54269)
This commit is contained in:
parent
4ef9269790
commit
6285c7775b
3 changed files with 586 additions and 279 deletions
|
@ -25,19 +25,12 @@ from .const import (
|
|||
DOMAIN,
|
||||
KEY_STATUS,
|
||||
KEY_STATUS_DISPLAY,
|
||||
SENSOR_NAME,
|
||||
SENSOR_TYPES,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
SENSOR_DICT = {
|
||||
sensor_id: sensor_spec[SENSOR_NAME]
|
||||
for sensor_id, sensor_spec in SENSOR_TYPES.items()
|
||||
}
|
||||
|
||||
|
||||
def _base_schema(discovery_info):
|
||||
"""Generate base schema."""
|
||||
base_schema = {}
|
||||
|
@ -59,15 +52,15 @@ def _resource_schema_base(available_resources, selected_resources):
|
|||
"""Resource selection schema."""
|
||||
|
||||
known_available_resources = {
|
||||
sensor_id: sensor[SENSOR_NAME]
|
||||
for sensor_id, sensor in SENSOR_TYPES.items()
|
||||
sensor_id: sensor_desc.name
|
||||
for sensor_id, sensor_desc in SENSOR_TYPES.items()
|
||||
if sensor_id in available_resources
|
||||
}
|
||||
|
||||
if KEY_STATUS in known_available_resources:
|
||||
known_available_resources[KEY_STATUS_DISPLAY] = SENSOR_TYPES[
|
||||
KEY_STATUS_DISPLAY
|
||||
][SENSOR_NAME]
|
||||
].name
|
||||
|
||||
return {
|
||||
vol.Required(CONF_RESOURCES, default=selected_resources): cv.multi_select(
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
"""The nut component."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ELECTRIC_CURRENT_AMPERE,
|
||||
|
@ -40,246 +47,559 @@ PYNUT_MODEL = "model"
|
|||
PYNUT_FIRMWARE = "firmware"
|
||||
PYNUT_NAME = "name"
|
||||
|
||||
SENSOR_TYPES = {
|
||||
"ups.status.display": ["Status", "", "mdi:information-outline", None],
|
||||
"ups.status": ["Status Data", "", "mdi:information-outline", None],
|
||||
"ups.alarm": ["Alarms", "", "mdi:alarm", None],
|
||||
"ups.temperature": [
|
||||
"UPS Temperature",
|
||||
TEMP_CELSIUS,
|
||||
None,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
],
|
||||
"ups.load": ["Load", PERCENTAGE, "mdi:gauge", None],
|
||||
"ups.load.high": ["Overload Setting", PERCENTAGE, "mdi:gauge", None],
|
||||
"ups.id": ["System identifier", "", "mdi:information-outline", None],
|
||||
"ups.delay.start": ["Load Restart Delay", TIME_SECONDS, "mdi:timer-outline", None],
|
||||
"ups.delay.reboot": ["UPS Reboot Delay", TIME_SECONDS, "mdi:timer-outline", None],
|
||||
"ups.delay.shutdown": [
|
||||
"UPS Shutdown Delay",
|
||||
TIME_SECONDS,
|
||||
"mdi:timer-outline",
|
||||
None,
|
||||
],
|
||||
"ups.timer.start": ["Load Start Timer", TIME_SECONDS, "mdi:timer-outline", None],
|
||||
"ups.timer.reboot": ["Load Reboot Timer", TIME_SECONDS, "mdi:timer-outline", None],
|
||||
"ups.timer.shutdown": [
|
||||
"Load Shutdown Timer",
|
||||
TIME_SECONDS,
|
||||
"mdi:timer-outline",
|
||||
None,
|
||||
],
|
||||
"ups.test.interval": [
|
||||
"Self-Test Interval",
|
||||
TIME_SECONDS,
|
||||
"mdi:timer-outline",
|
||||
None,
|
||||
],
|
||||
"ups.test.result": ["Self-Test Result", "", "mdi:information-outline", None],
|
||||
"ups.test.date": ["Self-Test Date", "", "mdi:calendar", None],
|
||||
"ups.display.language": ["Language", "", "mdi:information-outline", None],
|
||||
"ups.contacts": ["External Contacts", "", "mdi:information-outline", None],
|
||||
"ups.efficiency": ["Efficiency", PERCENTAGE, "mdi:gauge", None],
|
||||
"ups.power": ["Current Apparent Power", POWER_VOLT_AMPERE, "mdi:flash", None],
|
||||
"ups.power.nominal": ["Nominal Power", POWER_VOLT_AMPERE, "mdi:flash", None],
|
||||
"ups.realpower": [
|
||||
"Current Real Power",
|
||||
POWER_WATT,
|
||||
None,
|
||||
DEVICE_CLASS_POWER,
|
||||
],
|
||||
"ups.realpower.nominal": [
|
||||
"Nominal Real Power",
|
||||
POWER_WATT,
|
||||
None,
|
||||
DEVICE_CLASS_POWER,
|
||||
],
|
||||
"ups.beeper.status": ["Beeper Status", "", "mdi:information-outline", None],
|
||||
"ups.type": ["UPS Type", "", "mdi:information-outline", None],
|
||||
"ups.watchdog.status": ["Watchdog Status", "", "mdi:information-outline", None],
|
||||
"ups.start.auto": ["Start on AC", "", "mdi:information-outline", None],
|
||||
"ups.start.battery": ["Start on Battery", "", "mdi:information-outline", None],
|
||||
"ups.start.reboot": ["Reboot on Battery", "", "mdi:information-outline", None],
|
||||
"ups.shutdown": ["Shutdown Ability", "", "mdi:information-outline", None],
|
||||
"battery.charge": [
|
||||
"Battery Charge",
|
||||
PERCENTAGE,
|
||||
None,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
],
|
||||
"battery.charge.low": ["Low Battery Setpoint", PERCENTAGE, "mdi:gauge", None],
|
||||
"battery.charge.restart": [
|
||||
"Minimum Battery to Start",
|
||||
PERCENTAGE,
|
||||
"mdi:gauge",
|
||||
None,
|
||||
],
|
||||
"battery.charge.warning": [
|
||||
"Warning Battery Setpoint",
|
||||
PERCENTAGE,
|
||||
"mdi:gauge",
|
||||
None,
|
||||
],
|
||||
"battery.charger.status": ["Charging Status", "", "mdi:information-outline", None],
|
||||
"battery.voltage": [
|
||||
"Battery Voltage",
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
None,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
],
|
||||
"battery.voltage.nominal": [
|
||||
"Nominal Battery Voltage",
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
None,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
],
|
||||
"battery.voltage.low": [
|
||||
"Low Battery Voltage",
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
None,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
],
|
||||
"battery.voltage.high": [
|
||||
"High Battery Voltage",
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
None,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
],
|
||||
"battery.capacity": ["Battery Capacity", "Ah", "mdi:flash", None],
|
||||
"battery.current": [
|
||||
"Battery Current",
|
||||
ELECTRIC_CURRENT_AMPERE,
|
||||
"mdi:flash",
|
||||
None,
|
||||
],
|
||||
"battery.current.total": [
|
||||
"Total Battery Current",
|
||||
ELECTRIC_CURRENT_AMPERE,
|
||||
"mdi:flash",
|
||||
None,
|
||||
],
|
||||
"battery.temperature": [
|
||||
"Battery Temperature",
|
||||
TEMP_CELSIUS,
|
||||
None,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
],
|
||||
"battery.runtime": ["Battery Runtime", TIME_SECONDS, "mdi:timer-outline", None],
|
||||
"battery.runtime.low": [
|
||||
"Low Battery Runtime",
|
||||
TIME_SECONDS,
|
||||
"mdi:timer-outline",
|
||||
None,
|
||||
],
|
||||
"battery.runtime.restart": [
|
||||
"Minimum Battery Runtime to Start",
|
||||
TIME_SECONDS,
|
||||
"mdi:timer-outline",
|
||||
None,
|
||||
],
|
||||
"battery.alarm.threshold": [
|
||||
"Battery Alarm Threshold",
|
||||
"",
|
||||
"mdi:information-outline",
|
||||
None,
|
||||
],
|
||||
"battery.date": ["Battery Date", "", "mdi:calendar", None],
|
||||
"battery.mfr.date": ["Battery Manuf. Date", "", "mdi:calendar", None],
|
||||
"battery.packs": ["Number of Batteries", "", "mdi:information-outline", None],
|
||||
"battery.packs.bad": [
|
||||
"Number of Bad Batteries",
|
||||
"",
|
||||
"mdi:information-outline",
|
||||
None,
|
||||
],
|
||||
"battery.type": ["Battery Chemistry", "", "mdi:information-outline", None],
|
||||
"input.sensitivity": [
|
||||
"Input Power Sensitivity",
|
||||
"",
|
||||
"mdi:information-outline",
|
||||
None,
|
||||
],
|
||||
"input.transfer.low": [
|
||||
"Low Voltage Transfer",
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
None,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
],
|
||||
"input.transfer.high": [
|
||||
"High Voltage Transfer",
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
None,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
],
|
||||
"input.transfer.reason": [
|
||||
"Voltage Transfer Reason",
|
||||
"",
|
||||
"mdi:information-outline",
|
||||
None,
|
||||
],
|
||||
"input.voltage": [
|
||||
"Input Voltage",
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
None,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
],
|
||||
"input.voltage.nominal": [
|
||||
"Nominal Input Voltage",
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
None,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
],
|
||||
"input.frequency": ["Input Line Frequency", FREQUENCY_HERTZ, "mdi:flash", None],
|
||||
"input.frequency.nominal": [
|
||||
"Nominal Input Line Frequency",
|
||||
FREQUENCY_HERTZ,
|
||||
"mdi:flash",
|
||||
None,
|
||||
],
|
||||
"input.frequency.status": [
|
||||
"Input Frequency Status",
|
||||
"",
|
||||
"mdi:information-outline",
|
||||
None,
|
||||
],
|
||||
"output.current": ["Output Current", ELECTRIC_CURRENT_AMPERE, "mdi:flash", None],
|
||||
"output.current.nominal": [
|
||||
"Nominal Output Current",
|
||||
ELECTRIC_CURRENT_AMPERE,
|
||||
"mdi:flash",
|
||||
None,
|
||||
],
|
||||
"output.voltage": [
|
||||
"Output Voltage",
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
None,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
],
|
||||
"output.voltage.nominal": [
|
||||
"Nominal Output Voltage",
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
None,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
],
|
||||
"output.frequency": ["Output Frequency", FREQUENCY_HERTZ, "mdi:flash", None],
|
||||
"output.frequency.nominal": [
|
||||
"Nominal Output Frequency",
|
||||
FREQUENCY_HERTZ,
|
||||
"mdi:flash",
|
||||
None,
|
||||
],
|
||||
"ambient.humidity": [
|
||||
"Ambient Humidity",
|
||||
PERCENTAGE,
|
||||
None,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
],
|
||||
"ambient.temperature": [
|
||||
"Ambient Temperature",
|
||||
TEMP_CELSIUS,
|
||||
None,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
],
|
||||
SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
|
||||
"ups.status.display": SensorEntityDescription(
|
||||
key="ups.status.display",
|
||||
name="Status",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.status": SensorEntityDescription(
|
||||
key="ups.status",
|
||||
name="Status Data",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.alarm": SensorEntityDescription(
|
||||
key="ups.alarm",
|
||||
name="Alarms",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:alarm",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.temperature": SensorEntityDescription(
|
||||
key="ups.temperature",
|
||||
name="UPS Temperature",
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"ups.load": SensorEntityDescription(
|
||||
key="ups.load",
|
||||
name="Load",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:gauge",
|
||||
device_class=None,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"ups.load.high": SensorEntityDescription(
|
||||
key="ups.load.high",
|
||||
name="Overload Setting",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:gauge",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.id": SensorEntityDescription(
|
||||
key="ups.id",
|
||||
name="System identifier",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.delay.start": SensorEntityDescription(
|
||||
key="ups.delay.start",
|
||||
name="Load Restart Delay",
|
||||
unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:timer-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.delay.reboot": SensorEntityDescription(
|
||||
key="ups.delay.reboot",
|
||||
name="UPS Reboot Delay",
|
||||
unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:timer-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.delay.shutdown": SensorEntityDescription(
|
||||
key="ups.delay.shutdown",
|
||||
name="UPS Shutdown Delay",
|
||||
unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:timer-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.timer.start": SensorEntityDescription(
|
||||
key="ups.timer.start",
|
||||
name="Load Start Timer",
|
||||
unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:timer-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.timer.reboot": SensorEntityDescription(
|
||||
key="ups.timer.reboot",
|
||||
name="Load Reboot Timer",
|
||||
unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:timer-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.timer.shutdown": SensorEntityDescription(
|
||||
key="ups.timer.shutdown",
|
||||
name="Load Shutdown Timer",
|
||||
unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:timer-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.test.interval": SensorEntityDescription(
|
||||
key="ups.test.interval",
|
||||
name="Self-Test Interval",
|
||||
unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:timer-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.test.result": SensorEntityDescription(
|
||||
key="ups.test.result",
|
||||
name="Self-Test Result",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.test.date": SensorEntityDescription(
|
||||
key="ups.test.date",
|
||||
name="Self-Test Date",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:calendar",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.display.language": SensorEntityDescription(
|
||||
key="ups.display.language",
|
||||
name="Language",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.contacts": SensorEntityDescription(
|
||||
key="ups.contacts",
|
||||
name="External Contacts",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.efficiency": SensorEntityDescription(
|
||||
key="ups.efficiency",
|
||||
name="Efficiency",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:gauge",
|
||||
device_class=None,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"ups.power": SensorEntityDescription(
|
||||
key="ups.power",
|
||||
name="Current Apparent Power",
|
||||
unit_of_measurement=POWER_VOLT_AMPERE,
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"ups.power.nominal": SensorEntityDescription(
|
||||
key="ups.power.nominal",
|
||||
name="Nominal Power",
|
||||
unit_of_measurement=POWER_VOLT_AMPERE,
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.realpower": SensorEntityDescription(
|
||||
key="ups.realpower",
|
||||
name="Current Real Power",
|
||||
unit_of_measurement=POWER_WATT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"ups.realpower.nominal": SensorEntityDescription(
|
||||
key="ups.realpower.nominal",
|
||||
name="Nominal Real Power",
|
||||
unit_of_measurement=POWER_WATT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.beeper.status": SensorEntityDescription(
|
||||
key="ups.beeper.status",
|
||||
name="Beeper Status",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.type": SensorEntityDescription(
|
||||
key="ups.type",
|
||||
name="UPS Type",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.watchdog.status": SensorEntityDescription(
|
||||
key="ups.watchdog.status",
|
||||
name="Watchdog Status",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.start.auto": SensorEntityDescription(
|
||||
key="ups.start.auto",
|
||||
name="Start on AC",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.start.battery": SensorEntityDescription(
|
||||
key="ups.start.battery",
|
||||
name="Start on Battery",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.start.reboot": SensorEntityDescription(
|
||||
key="ups.start.reboot",
|
||||
name="Reboot on Battery",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ups.shutdown": SensorEntityDescription(
|
||||
key="ups.shutdown",
|
||||
name="Shutdown Ability",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.charge": SensorEntityDescription(
|
||||
key="battery.charge",
|
||||
name="Battery Charge",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_BATTERY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"battery.charge.low": SensorEntityDescription(
|
||||
key="battery.charge.low",
|
||||
name="Low Battery Setpoint",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:gauge",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.charge.restart": SensorEntityDescription(
|
||||
key="battery.charge.restart",
|
||||
name="Minimum Battery to Start",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:gauge",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.charge.warning": SensorEntityDescription(
|
||||
key="battery.charge.warning",
|
||||
name="Warning Battery Setpoint",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:gauge",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.charger.status": SensorEntityDescription(
|
||||
key="battery.charger.status",
|
||||
name="Charging Status",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.voltage": SensorEntityDescription(
|
||||
key="battery.voltage",
|
||||
name="Battery Voltage",
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"battery.voltage.nominal": SensorEntityDescription(
|
||||
key="battery.voltage.nominal",
|
||||
name="Nominal Battery Voltage",
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.voltage.low": SensorEntityDescription(
|
||||
key="battery.voltage.low",
|
||||
name="Low Battery Voltage",
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.voltage.high": SensorEntityDescription(
|
||||
key="battery.voltage.high",
|
||||
name="High Battery Voltage",
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.capacity": SensorEntityDescription(
|
||||
key="battery.capacity",
|
||||
name="Battery Capacity",
|
||||
unit_of_measurement="Ah",
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.current": SensorEntityDescription(
|
||||
key="battery.current",
|
||||
name="Battery Current",
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"battery.current.total": SensorEntityDescription(
|
||||
key="battery.current.total",
|
||||
name="Total Battery Current",
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.temperature": SensorEntityDescription(
|
||||
key="battery.temperature",
|
||||
name="Battery Temperature",
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"battery.runtime": SensorEntityDescription(
|
||||
key="battery.runtime",
|
||||
name="Battery Runtime",
|
||||
unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:timer-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.runtime.low": SensorEntityDescription(
|
||||
key="battery.runtime.low",
|
||||
name="Low Battery Runtime",
|
||||
unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:timer-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.runtime.restart": SensorEntityDescription(
|
||||
key="battery.runtime.restart",
|
||||
name="Minimum Battery Runtime to Start",
|
||||
unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:timer-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.alarm.threshold": SensorEntityDescription(
|
||||
key="battery.alarm.threshold",
|
||||
name="Battery Alarm Threshold",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.date": SensorEntityDescription(
|
||||
key="battery.date",
|
||||
name="Battery Date",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:calendar",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.mfr.date": SensorEntityDescription(
|
||||
key="battery.mfr.date",
|
||||
name="Battery Manuf. Date",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:calendar",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.packs": SensorEntityDescription(
|
||||
key="battery.packs",
|
||||
name="Number of Batteries",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.packs.bad": SensorEntityDescription(
|
||||
key="battery.packs.bad",
|
||||
name="Number of Bad Batteries",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"battery.type": SensorEntityDescription(
|
||||
key="battery.type",
|
||||
name="Battery Chemistry",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"input.sensitivity": SensorEntityDescription(
|
||||
key="input.sensitivity",
|
||||
name="Input Power Sensitivity",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"input.transfer.low": SensorEntityDescription(
|
||||
key="input.transfer.low",
|
||||
name="Low Voltage Transfer",
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=None,
|
||||
),
|
||||
"input.transfer.high": SensorEntityDescription(
|
||||
key="input.transfer.high",
|
||||
name="High Voltage Transfer",
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=None,
|
||||
),
|
||||
"input.transfer.reason": SensorEntityDescription(
|
||||
key="input.transfer.reason",
|
||||
name="Voltage Transfer Reason",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"input.voltage": SensorEntityDescription(
|
||||
key="input.voltage",
|
||||
name="Input Voltage",
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"input.voltage.nominal": SensorEntityDescription(
|
||||
key="input.voltage.nominal",
|
||||
name="Nominal Input Voltage",
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=None,
|
||||
),
|
||||
"input.frequency": SensorEntityDescription(
|
||||
key="input.frequency",
|
||||
name="Input Line Frequency",
|
||||
unit_of_measurement=FREQUENCY_HERTZ,
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"input.frequency.nominal": SensorEntityDescription(
|
||||
key="input.frequency.nominal",
|
||||
name="Nominal Input Line Frequency",
|
||||
unit_of_measurement=FREQUENCY_HERTZ,
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"input.frequency.status": SensorEntityDescription(
|
||||
key="input.frequency.status",
|
||||
name="Input Frequency Status",
|
||||
unit_of_measurement=None,
|
||||
icon="mdi:information-outline",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"output.current": SensorEntityDescription(
|
||||
key="output.current",
|
||||
name="Output Current",
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"output.current.nominal": SensorEntityDescription(
|
||||
key="output.current.nominal",
|
||||
name="Nominal Output Current",
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"output.voltage": SensorEntityDescription(
|
||||
key="output.voltage",
|
||||
name="Output Voltage",
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"output.voltage.nominal": SensorEntityDescription(
|
||||
key="output.voltage.nominal",
|
||||
name="Nominal Output Voltage",
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=None,
|
||||
),
|
||||
"output.frequency": SensorEntityDescription(
|
||||
key="output.frequency",
|
||||
name="Output Frequency",
|
||||
unit_of_measurement=FREQUENCY_HERTZ,
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"output.frequency.nominal": SensorEntityDescription(
|
||||
key="output.frequency.nominal",
|
||||
name="Nominal Output Frequency",
|
||||
unit_of_measurement=FREQUENCY_HERTZ,
|
||||
icon="mdi:flash",
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
),
|
||||
"ambient.humidity": SensorEntityDescription(
|
||||
key="ambient.humidity",
|
||||
name="Ambient Humidity",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"ambient.temperature": SensorEntityDescription(
|
||||
key="ambient.temperature",
|
||||
name="Ambient Temperature",
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
icon=None,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}
|
||||
|
||||
STATE_TYPES = {
|
||||
|
@ -299,8 +619,3 @@ STATE_TYPES = {
|
|||
"FSD": "Forced Shutdown",
|
||||
"ALARM": "Alarm",
|
||||
}
|
||||
|
||||
SENSOR_NAME = 0
|
||||
SENSOR_UNIT = 1
|
||||
SENSOR_ICON = 2
|
||||
SENSOR_DEVICE_CLASS = 3
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
"""Provides a sensor to track various status aspects of a UPS."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.components.nut import PyNUTData
|
||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
||||
from homeassistant.const import ATTR_STATE, CONF_RESOURCES, STATE_UNKNOWN
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
|
||||
from .const import (
|
||||
COORDINATOR,
|
||||
|
@ -16,11 +22,7 @@ from .const import (
|
|||
PYNUT_MODEL,
|
||||
PYNUT_NAME,
|
||||
PYNUT_UNIQUE_ID,
|
||||
SENSOR_DEVICE_CLASS,
|
||||
SENSOR_ICON,
|
||||
SENSOR_NAME,
|
||||
SENSOR_TYPES,
|
||||
SENSOR_UNIT,
|
||||
STATE_TYPES,
|
||||
)
|
||||
|
||||
|
@ -60,7 +62,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
coordinator,
|
||||
data,
|
||||
name.title(),
|
||||
sensor_type,
|
||||
SENSOR_TYPES[sensor_type],
|
||||
unique_id,
|
||||
manufacturer,
|
||||
model,
|
||||
|
@ -82,18 +84,18 @@ class NUTSensor(CoordinatorEntity, SensorEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator,
|
||||
data,
|
||||
name,
|
||||
sensor_type,
|
||||
unique_id,
|
||||
manufacturer,
|
||||
model,
|
||||
firmware,
|
||||
):
|
||||
coordinator: DataUpdateCoordinator,
|
||||
data: PyNUTData,
|
||||
name: str,
|
||||
sensor_description: SensorEntityDescription,
|
||||
unique_id: str,
|
||||
manufacturer: str | None,
|
||||
model: str | None,
|
||||
firmware: str | None,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
self._type = sensor_type
|
||||
self.entity_description = sensor_description
|
||||
self._manufacturer = manufacturer
|
||||
self._firmware = firmware
|
||||
self._model = model
|
||||
|
@ -101,10 +103,7 @@ class NUTSensor(CoordinatorEntity, SensorEntity):
|
|||
self._data = data
|
||||
self._unique_id = unique_id
|
||||
|
||||
self._attr_device_class = SENSOR_TYPES[self._type][SENSOR_DEVICE_CLASS]
|
||||
self._attr_icon = SENSOR_TYPES[self._type][SENSOR_ICON]
|
||||
self._attr_name = f"{name} {SENSOR_TYPES[sensor_type][SENSOR_NAME]}"
|
||||
self._attr_unit_of_measurement = SENSOR_TYPES[sensor_type][SENSOR_UNIT]
|
||||
self._attr_name = f"{name} {sensor_description.name}"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
|
@ -128,16 +127,16 @@ class NUTSensor(CoordinatorEntity, SensorEntity):
|
|||
"""Sensor Unique id."""
|
||||
if not self._unique_id:
|
||||
return None
|
||||
return f"{self._unique_id}_{self._type}"
|
||||
return f"{self._unique_id}_{self.entity_description.key}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return entity state from ups."""
|
||||
if not self._data.status:
|
||||
return None
|
||||
if self._type == KEY_STATUS_DISPLAY:
|
||||
if self.entity_description.key == KEY_STATUS_DISPLAY:
|
||||
return _format_display_state(self._data.status)
|
||||
return self._data.status.get(self._type)
|
||||
return self._data.status.get(self.entity_description.key)
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue