Skip to content

Commit

Permalink
Merge pull request #88 from tijsverkoyen/86-inverter-efficiency-as-pe…
Browse files Browse the repository at this point in the history
…rcentage

86 inverter efficiency as percentage
  • Loading branch information
tijsverkoyen authored Apr 14, 2023
2 parents 9a040a1 + 1208ff5 commit fd3014f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 37 deletions.
8 changes: 4 additions & 4 deletions custom_components/fusion_solar/fusion_solar/energy_sensor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging

from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING, SensorEntity
from homeassistant.const import DEVICE_CLASS_ENERGY, UnitOfEnergy
from homeassistant.components.sensor import SensorEntity, SensorDeviceClass, SensorStateClass
from homeassistant.const import UnitOfEnergy

from .const import ATTR_TOTAL_LIFETIME_ENERGY, ATTR_REALTIME_POWER

Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__(

@property
def device_class(self) -> str:
return DEVICE_CLASS_ENERGY
return SensorDeviceClass.ENERGY

@property
def unique_id(self) -> str:
Expand Down Expand Up @@ -84,7 +84,7 @@ def unit_of_measurement(self) -> str:

@property
def state_class(self) -> str:
return STATE_CLASS_TOTAL_INCREASING
return SensorStateClass.TOTAL_INCREASING

@property
def native_value(self) -> str:
Expand Down
5 changes: 3 additions & 2 deletions custom_components/fusion_solar/fusion_solar/power_entity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from homeassistant.core import callback
from homeassistant.const import DEVICE_CLASS_POWER, UnitOfPower
from homeassistant.const import UnitOfPower
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.helpers.entity import Entity

Expand Down Expand Up @@ -27,7 +28,7 @@ def __init__(

@property
def device_class(self):
return DEVICE_CLASS_POWER
return SensorDeviceClass.POWER

@property
def unique_id(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

from homeassistant.core import callback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, STATE_CLASS_TOTAL, \
SensorEntity
from homeassistant.components.binary_sensor import DEVICE_CLASS_CONNECTIVITY, BinarySensorEntity
from homeassistant.const import DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_CURRENT, DEVICE_CLASS_ENERGY, \
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_POWER_FACTOR, PERCENTAGE, DEVICE_CLASS_FREQUENCY, DEVICE_CLASS_POWER, \
DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_BATTERY, UnitOfEnergy, UnitOfPower, UnitOfTemperature, UnitOfElectricCurrent, \
from homeassistant.components.sensor import SensorEntity, SensorStateClass, SensorDeviceClass
from homeassistant.components.binary_sensor import BinarySensorEntity, BinarySensorDeviceClass
from homeassistant.const import PERCENTAGE, UnitOfEnergy, UnitOfPower, UnitOfTemperature, UnitOfElectricCurrent, \
UnitOfElectricPotential, UnitOfFrequency

from .openapi.device import FusionSolarDevice
Expand Down Expand Up @@ -95,77 +92,77 @@ def translation_key(self) -> str:
class FusionSolarRealtimeDeviceDataVoltageSensor(FusionSolarRealtimeDeviceDataSensor):
@property
def device_class(self) -> str:
return DEVICE_CLASS_VOLTAGE
return SensorDeviceClass.VOLTAGE

@property
def unit_of_measurement(self) -> str:
return UnitOfElectricPotential.VOLT

@property
def state_class(self) -> str:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT


class FusionSolarRealtimeDeviceDataCurrentSensor(FusionSolarRealtimeDeviceDataSensor):
@property
def device_class(self) -> str:
return DEVICE_CLASS_CURRENT
return SensorDeviceClass.CURRENT

@property
def unit_of_measurement(self) -> str:
return UnitOfElectricCurrent.AMPERE

@property
def state_class(self) -> str:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT


class FusionSolarRealtimeDeviceDataEnergySensor(FusionSolarRealtimeDeviceDataSensor):
@property
def device_class(self) -> str:
return DEVICE_CLASS_ENERGY
return SensorDeviceClass.ENERGY

@property
def unit_of_measurement(self) -> str:
return UnitOfEnergy.KILO_WATT_HOUR

@property
def state_class(self) -> str:
return STATE_CLASS_TOTAL
return SensorStateClass.TOTAL


class FusionSolarRealtimeDeviceDataEnergyTotalIncreasingSensor(FusionSolarRealtimeDeviceDataEnergySensor):
@property
def state_class(self) -> str:
return STATE_CLASS_TOTAL_INCREASING
return SensorStateClass.TOTAL_INCREASING


class FusionSolarRealtimeDeviceDataTemperatureSensor(FusionSolarRealtimeDeviceDataSensor):
@property
def device_class(self) -> str:
return DEVICE_CLASS_TEMPERATURE
return SensorDeviceClass.TEMPERATURE

@property
def unit_of_measurement(self) -> str:
return UnitOfTemperature.CELSIUS

@property
def state_class(self) -> str:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT


class FusionSolarRealtimeDeviceDataPowerFactorSensor(FusionSolarRealtimeDeviceDataSensor):
@property
def device_class(self) -> str:
return DEVICE_CLASS_POWER_FACTOR
return SensorDeviceClass.POWER_FACTOR

@property
def unit_of_measurement(self) -> str:
return PERCENTAGE

@property
def state_class(self) -> str:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT

@property
def state(self) -> str:
Expand All @@ -180,29 +177,29 @@ def state(self) -> str:
class FusionSolarRealtimeDeviceDataFrequencySensor(FusionSolarRealtimeDeviceDataSensor):
@property
def device_class(self) -> str:
return DEVICE_CLASS_FREQUENCY
return SensorDeviceClass.FREQUENCY

@property
def unit_of_measurement(self) -> str:
return UnitOfFrequency.HERTZ

@property
def state_class(self) -> str:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT


class FusionSolarRealtimeDeviceDataPowerSensor(FusionSolarRealtimeDeviceDataSensor):
@property
def device_class(self) -> str:
return DEVICE_CLASS_POWER
return SensorDeviceClass.POWER

@property
def unit_of_measurement(self) -> str:
return UnitOfPower.KILO_WATT

@property
def state_class(self) -> str:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT


class FusionSolarRealtimeDeviceDataPowerInWattSensor(FusionSolarRealtimeDeviceDataPowerSensor):
Expand All @@ -222,7 +219,7 @@ def unit_of_measurement(self) -> str:

@property
def state_class(self) -> str:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT


class FusionSolarRealtimeDeviceDataReactivePowerInVarSensor(FusionSolarRealtimeDeviceDataReactivePowerSensor):
Expand All @@ -242,7 +239,7 @@ def unit_of_measurement(self) -> str:

@property
def state_class(self) -> str:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT


class FusionSolarRealtimeDeviceDataWindSpeedSensor(FusionSolarRealtimeDeviceDataSensor):
Expand All @@ -256,27 +253,27 @@ def unit_of_measurement(self) -> str:

@property
def state_class(self) -> str:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT


class FusionSolarRealtimeDeviceDataBatterySensor(FusionSolarRealtimeDeviceDataSensor):
@property
def device_class(self) -> str:
return DEVICE_CLASS_BATTERY
return SensorDeviceClass.BATTERY

@property
def unit_of_measurement(self) -> str:
return PERCENTAGE

@property
def state_class(self) -> str:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT


class FusionSolarRealtimeDeviceDataTimestampSensor(FusionSolarRealtimeDeviceDataSensor):
@property
def device_class(self) -> str:
return DEVICE_CLASS_TIMESTAMP
return SensorDeviceClass.TIMESTAMP

@property
def state(self) -> datetime:
Expand All @@ -288,6 +285,16 @@ def state(self) -> datetime:
return datetime.datetime.fromtimestamp(state / 1000)


class FusionSolarRealtimeDeviceDataPercentageSensor(FusionSolarRealtimeDeviceDataSensor):
@property
def unit_of_measurement(self) -> str | None:
return PERCENTAGE

@property
def state_class(self) -> str:
return SensorStateClass.MEASUREMENT


class FusionSolarRealtimeDeviceDataBinarySensor(CoordinatorEntity, BinarySensorEntity):
"""Base class for all FusionSolarRealtimeDeviceDataBinarySensor sensors."""

Expand Down Expand Up @@ -339,7 +346,7 @@ def _handle_coordinator_update(self):
class FusionSolarRealtimeDeviceDataStateBinarySensor(FusionSolarRealtimeDeviceDataBinarySensor):
@property
def device_class(self) -> str:
return DEVICE_CLASS_CONNECTIVITY
return BinarySensorDeviceClass.CONNECTIVITY

@property
def is_on(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/fusion_solar/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/tijsverkoyen/HomeAssistant-FusionSolar/issues",
"requirements": [],
"version": "2.5.0"
"version": "2.5.1"
}
4 changes: 2 additions & 2 deletions custom_components/fusion_solar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ async def add_entities_for_stations(hass, async_add_entities, stations, api: Fus
{'class': 'FusionSolarRealtimeDeviceDataCurrentSensor', 'attribute': 'a_i', 'name': 'Phase A current'},
{'class': 'FusionSolarRealtimeDeviceDataCurrentSensor', 'attribute': 'b_i', 'name': 'Phase B current'},
{'class': 'FusionSolarRealtimeDeviceDataCurrentSensor', 'attribute': 'c_i', 'name': 'Phase C current'},
{'class': 'FusionSolarRealtimeDeviceDataSensor', 'attribute': 'efficiency',
{'class': 'FusionSolarRealtimeDeviceDataPercentageSensor', 'attribute': 'efficiency',
'name': 'Inverter efficiency % (manufacturer)'},
{'class': 'FusionSolarRealtimeDeviceDataTemperatureSensor', 'attribute': 'temperature',
'name': 'Inverter internal temperature'},
Expand Down Expand Up @@ -449,7 +449,7 @@ async def add_entities_for_stations(hass, async_add_entities, stations, api: Fus
{'class': 'FusionSolarRealtimeDeviceDataCurrentSensor', 'attribute': 'a_i', 'name': 'Phase A current'},
{'class': 'FusionSolarRealtimeDeviceDataCurrentSensor', 'attribute': 'b_i', 'name': 'Phase B current'},
{'class': 'FusionSolarRealtimeDeviceDataCurrentSensor', 'attribute': 'c_i', 'name': 'Phase C current'},
{'class': 'FusionSolarRealtimeDeviceDataSensor', 'attribute': 'efficiency',
{'class': 'FusionSolarRealtimeDeviceDataPercentageSensor', 'attribute': 'efficiency',
'name': 'Inverter efficiency % (manufacturer)'},
{'class': 'FusionSolarRealtimeDeviceDataTemperatureSensor', 'attribute': 'temperature',
'name': 'Inverter internal temperature'},
Expand Down

0 comments on commit fd3014f

Please sign in to comment.