Use new enums in solaredge (#62373)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-20 18:16:53 +01:00 committed by GitHub
parent c931044d46
commit 527d3a9e5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 34 deletions

View File

@ -2,18 +2,8 @@
from datetime import timedelta from datetime import timedelta
import logging import logging
from homeassistant.components.sensor import ( from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
STATE_CLASS_MEASUREMENT, from homeassistant.const import ENERGY_WATT_HOUR, PERCENTAGE, POWER_WATT
STATE_CLASS_TOTAL,
STATE_CLASS_TOTAL_INCREASING,
)
from homeassistant.const import (
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
ENERGY_WATT_HOUR,
PERCENTAGE,
POWER_WATT,
)
from .models import SolarEdgeSensorEntityDescription from .models import SolarEdgeSensorEntityDescription
@ -43,9 +33,9 @@ SENSOR_TYPES = [
json_key="lifeTimeData", json_key="lifeTimeData",
name="Lifetime energy", name="Lifetime energy",
icon="mdi:solar-power", icon="mdi:solar-power",
state_class=STATE_CLASS_TOTAL, state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(
key="energy_this_year", key="energy_this_year",
@ -54,7 +44,7 @@ SENSOR_TYPES = [
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
icon="mdi:solar-power", icon="mdi:solar-power",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(
key="energy_this_month", key="energy_this_month",
@ -63,7 +53,7 @@ SENSOR_TYPES = [
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
icon="mdi:solar-power", icon="mdi:solar-power",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(
key="energy_today", key="energy_today",
@ -72,16 +62,16 @@ SENSOR_TYPES = [
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
icon="mdi:solar-power", icon="mdi:solar-power",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(
key="current_power", key="current_power",
json_key="currentPower", json_key="currentPower",
name="Current Power", name="Current Power",
icon="mdi:solar-power", icon="mdi:solar-power",
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER, device_class=SensorDeviceClass.POWER,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(
key="site_details", key="site_details",
@ -151,52 +141,52 @@ SENSOR_TYPES = [
json_key="Purchased", json_key="Purchased",
name="Imported Energy", name="Imported Energy",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(
key="production_energy", key="production_energy",
json_key="Production", json_key="Production",
name="Production Energy", name="Production Energy",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(
key="consumption_energy", key="consumption_energy",
json_key="Consumption", json_key="Consumption",
name="Consumption Energy", name="Consumption Energy",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(
key="selfconsumption_energy", key="selfconsumption_energy",
json_key="SelfConsumption", json_key="SelfConsumption",
name="SelfConsumption Energy", name="SelfConsumption Energy",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(
key="feedin_energy", key="feedin_energy",
json_key="FeedIn", json_key="FeedIn",
name="Exported Energy", name="Exported Energy",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(
key="storage_level", key="storage_level",
json_key="STORAGE", json_key="STORAGE",
name="Storage Level", name="Storage Level",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
), ),
] ]

View File

@ -5,9 +5,8 @@ from typing import Any
from solaredge import Solaredge from solaredge import Solaredge
from homeassistant.components.sensor import SensorEntity from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DEVICE_CLASS_BATTERY, DEVICE_CLASS_POWER
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -203,7 +202,7 @@ class SolarEdgeEnergyDetailsSensor(SolarEdgeSensorEntity):
class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity): class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity):
"""Representation of an SolarEdge Monitoring API power flow sensor.""" """Representation of an SolarEdge Monitoring API power flow sensor."""
_attr_device_class = DEVICE_CLASS_POWER _attr_device_class = SensorDeviceClass.POWER
def __init__( def __init__(
self, self,
@ -230,7 +229,7 @@ class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity):
class SolarEdgeStorageLevelSensor(SolarEdgeSensorEntity): class SolarEdgeStorageLevelSensor(SolarEdgeSensorEntity):
"""Representation of an SolarEdge Monitoring API storage level sensor.""" """Representation of an SolarEdge Monitoring API storage level sensor."""
_attr_device_class = DEVICE_CLASS_BATTERY _attr_device_class = SensorDeviceClass.BATTERY
@property @property
def native_value(self) -> str | None: def native_value(self) -> str | None: