Skip to content

Commit

Permalink
Update sensor.py
Browse files Browse the repository at this point in the history
#50
Integration is using deprecated DEVICE_CLASS_*
  • Loading branch information
djansen1987 committed Mar 10, 2023
1 parent 8bc6e9d commit e0f42fe
Showing 1 changed file with 38 additions and 41 deletions.
79 changes: 38 additions & 41 deletions custom_components/saj_esolar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
STATE_CLASS_TOTAL_INCREASING,
SensorDeviceClass,
SensorStateClass,
SensorEntity,
SensorEntityDescription,
)
Expand All @@ -28,12 +29,8 @@
CONF_USERNAME,
CONF_PASSWORD,
CONF_SENSORS,
CONF_DEVICE_ID,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
ENERGY_KILO_WATT_HOUR,
POWER_WATT,
POWER_KILO_WATT,
PERCENTAGE,

)
Expand Down Expand Up @@ -136,7 +133,7 @@ def add_years(d, years):
name="nowPower",
icon="mdi:solar-power",
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
),
SensorEntityDescription(
key="runningState",
Expand All @@ -153,29 +150,29 @@ def add_years(d, years):
name="todayElectricity",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="monthElectricity",
name="monthElectricity",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="yearElectricity",
name="yearElectricity",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="totalElectricity",
name="totalElectricity",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="selfUseRate",
Expand All @@ -187,23 +184,23 @@ def add_years(d, years):
name="totalBuyElec",
icon="mdi:solar-panel",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="totalConsumpElec",
name="totalConsumpElec",
icon="mdi:solar-panel",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="totalSellElec",
name="totalSellElec",
icon="mdi:solar-panel",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="todayGridIncome",
Expand Down Expand Up @@ -270,45 +267,45 @@ def add_years(d, years):
name="peakPower",
icon="mdi:solar-panel",
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
),
SensorEntityDescription(
key="systemPower",
name="systemPower",
icon="mdi:solar-panel",
native_unit_of_measurement=POWER_KILO_WATT,
device_class=DEVICE_CLASS_POWER,
native_unit_of_measurement=POWER_WATT,
device_class=SensorDeviceClass.POWER,
),
SensorEntityDescription(
key="pvElec",
name="pvElec",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="useElec",
name="useElec",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="buyElec",
name="buyElec",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="sellElec",
name="sellElec",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="buyRate",
Expand All @@ -335,14 +332,14 @@ def add_years(d, years):
name="selfConsumedEnergy1",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="selfConsumedEnergy2",
name="selfConsumedEnergy2",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="plantTreeNum",
Expand All @@ -365,7 +362,7 @@ def add_years(d, years):
name="totalLoadPower",
icon="mdi:solar-panel",
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
),
SensorEntityDescription(
key="totalPvgenPower",
Expand All @@ -378,32 +375,32 @@ def add_years(d, years):
name="totalPvEnergy",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="totalLoadEnergy",
name="totalLoadEnergy",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="totalBuyEnergy",
name="totalBuyEnergy",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="totalSellEnergy",
name="totalSellEnergy",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
#h1
SensorEntityDescription(
Expand Down Expand Up @@ -481,16 +478,16 @@ def add_years(d, years):
name="chargeElec",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="dischargeElec",
name="dischargeElec",
icon="mdi:solar-panel-large",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
)

Expand Down

0 comments on commit e0f42fe

Please sign in to comment.