Use new enums in solax (#62376)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
c96606df68
commit
2f0b73c4ad
1 changed files with 15 additions and 25 deletions
|
@ -8,21 +8,11 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
STATE_CLASS_MEASUREMENT,
|
SensorDeviceClass,
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, TEMP_CELSIUS
|
||||||
CONF_IP_ADDRESS,
|
|
||||||
CONF_PORT,
|
|
||||||
DEVICE_CLASS_BATTERY,
|
|
||||||
DEVICE_CLASS_CURRENT,
|
|
||||||
DEVICE_CLASS_ENERGY,
|
|
||||||
DEVICE_CLASS_POWER,
|
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
DEVICE_CLASS_VOLTAGE,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
)
|
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
|
@ -51,24 +41,24 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||||
for sensor, (idx, unit) in api.inverter.sensor_map().items():
|
for sensor, (idx, unit) in api.inverter.sensor_map().items():
|
||||||
device_class = state_class = None
|
device_class = state_class = None
|
||||||
if unit == "C":
|
if unit == "C":
|
||||||
device_class = DEVICE_CLASS_TEMPERATURE
|
device_class = SensorDeviceClass.TEMPERATURE
|
||||||
state_class = STATE_CLASS_MEASUREMENT
|
state_class = SensorStateClass.MEASUREMENT
|
||||||
unit = TEMP_CELSIUS
|
unit = TEMP_CELSIUS
|
||||||
elif unit == "kWh":
|
elif unit == "kWh":
|
||||||
device_class = DEVICE_CLASS_ENERGY
|
device_class = SensorDeviceClass.ENERGY
|
||||||
state_class = STATE_CLASS_TOTAL_INCREASING
|
state_class = SensorStateClass.TOTAL_INCREASING
|
||||||
elif unit == "V":
|
elif unit == "V":
|
||||||
device_class = DEVICE_CLASS_VOLTAGE
|
device_class = SensorDeviceClass.VOLTAGE
|
||||||
state_class = STATE_CLASS_MEASUREMENT
|
state_class = SensorStateClass.MEASUREMENT
|
||||||
elif unit == "A":
|
elif unit == "A":
|
||||||
device_class = DEVICE_CLASS_CURRENT
|
device_class = SensorDeviceClass.CURRENT
|
||||||
state_class = STATE_CLASS_MEASUREMENT
|
state_class = SensorStateClass.MEASUREMENT
|
||||||
elif unit == "W":
|
elif unit == "W":
|
||||||
device_class = DEVICE_CLASS_POWER
|
device_class = SensorDeviceClass.POWER
|
||||||
state_class = STATE_CLASS_MEASUREMENT
|
state_class = SensorStateClass.MEASUREMENT
|
||||||
elif unit == "%":
|
elif unit == "%":
|
||||||
device_class = DEVICE_CLASS_BATTERY
|
device_class = SensorDeviceClass.BATTERY
|
||||||
state_class = STATE_CLASS_MEASUREMENT
|
state_class = SensorStateClass.MEASUREMENT
|
||||||
uid = f"{serial}-{idx}"
|
uid = f"{serial}-{idx}"
|
||||||
devices.append(Inverter(uid, serial, sensor, unit, state_class, device_class))
|
devices.append(Inverter(uid, serial, sensor, unit, state_class, device_class))
|
||||||
endpoint.sensors = devices
|
endpoint.sensors = devices
|
||||||
|
|
Loading…
Add table
Reference in a new issue