Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QOL improvements #125

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/.idea
11 changes: 8 additions & 3 deletions custom_components/alphaess/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
_LOGGER: logging.Logger = logging.getLogger(__package__)


async def process_value(value, default):
async def process_value(value, default=0):
if value is None or (isinstance(value, str) and value.strip() == ''):
return default
return value
Expand Down Expand Up @@ -48,10 +48,15 @@ async def _async_update_data(self):
if jsondata is not None:
for invertor in jsondata:

# data from system list data
inverterdata = {}
if invertor.get("minv") is not None:
inverterdata["Model"] = await process_value(invertor.get("minv"), 0)
inverterdata["EMS Status"] = await process_value(invertor.get("emsStatus"), 0)
inverterdata["Model"] = await process_value(invertor.get("minv"))

inverterdata["EMS Status"] = await process_value(invertor.get("emsStatus"))
inverterdata["Maximum Battery Capacity"] = await process_value(invertor.get("usCapacity"))
inverterdata["Current Capacity"] = await process_value(invertor.get("surplusCobat"))
inverterdata["Installed Capacity"] = await process_value(invertor.get("cobat"))

_sumdata = invertor.get("SumData", {})
_onedateenergy = invertor.get("OneDateEnergy", {})
Expand Down
3 changes: 3 additions & 0 deletions custom_components/alphaess/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ class AlphaESSNames(str, Enum):
SelfSufficiency = "Self Sufficiency"
SelfConsumption = "Self Consumption"
EmsStatus = "EMS Status"
usCapacity = "Maximum Battery Capacity"
cobat = "Installed Capacity"
surplusCobat = "Current Capacity"
15 changes: 13 additions & 2 deletions custom_components/alphaess/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def async_setup_entry(hass, entry, async_add_entities) -> None:
description.key: description for description in LIMITED_SENSOR_DESCRIPTIONS
}

_LOGGER.info(f"INITIALISING DEVICES")
_LOGGER.info(f"INITIALIZING DEVICES")
for serial, data in coordinator.data.items():
model = data.get("Model")
_LOGGER.info(f"Serial: {serial}, Model: {model}")
Expand Down Expand Up @@ -69,6 +69,8 @@ def __init__(self, coordinator, config, serial, key_supported_states, currency):
self._config = config
self._name = key_supported_states.name
self._native_unit_of_measurement = key_supported_states.native_unit_of_measurement
self._entity_category = key_supported_states.entity_category
self._icon = key_supported_states.icon
self._device_class = key_supported_states.device_class
self._state_class = key_supported_states.state_class
self._serial = serial
Expand Down Expand Up @@ -110,7 +112,6 @@ def native_unit_of_measurement(self):
self._native_unit_of_measurement = self._currency
return self._native_unit_of_measurement


@property
def device_class(self):
"""Return the device_class of the sensor."""
Expand All @@ -120,3 +121,13 @@ def device_class(self):
def state_class(self):
"""Return the state_class of the sensor."""
return self._state_class

@property
def entity_category(self):
"""Return the entity_category of the sensor."""
return self._entity_category

@property
def icon(self):
"""Return the entity_category of the sensor."""
return self._icon
59 changes: 53 additions & 6 deletions custom_components/alphaess/sensorlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.const import UnitOfEnergy, PERCENTAGE, UnitOfPower, CURRENCY_DOLLAR

from homeassistant.const import UnitOfEnergy, PERCENTAGE, UnitOfPower, CURRENCY_DOLLAR, EntityCategory

from .entity import AlphaESSSensorDescription
from .enums import AlphaESSNames


FULL_SENSOR_DESCRIPTIONS: List[AlphaESSSensorDescription] = [
AlphaESSSensorDescription(
key=AlphaESSNames.SolarProduction,
Expand Down Expand Up @@ -176,18 +173,21 @@
), AlphaESSSensorDescription(
key=AlphaESSNames.Income,
name="Total Income",
icon="mdi:cash-multiple",
native_unit_of_measurement=CURRENCY_DOLLAR,
device_class=SensorDeviceClass.MONETARY,
state_class=None,
), AlphaESSSensorDescription(
key=AlphaESSNames.SelfConsumption,
name="Self Consumption",
icon="mdi:percent",
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.POWER_FACTOR,
state_class=None,
), AlphaESSSensorDescription(
key=AlphaESSNames.SelfSufficiency,
name="Self Sufficiency",
icon="mdi:percent",
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.POWER_FACTOR,
state_class=None,
Expand All @@ -196,6 +196,29 @@
name="EMS Status",
device_class=SensorDeviceClass.ENUM,
state_class=None,
entity_category=EntityCategory.DIAGNOSTIC
),
AlphaESSSensorDescription(
key=AlphaESSNames.usCapacity,
name="Maximum Battery Capacity",
native_unit_of_measurement=PERCENTAGE,
state_class=None,
entity_category=EntityCategory.DIAGNOSTIC
),
AlphaESSSensorDescription(
key=AlphaESSNames.cobat,
name="Installed Capacity",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
state_class=None,
device_class=SensorDeviceClass.ENERGY,
entity_category=EntityCategory.DIAGNOSTIC
), AlphaESSSensorDescription(
key=AlphaESSNames.surplusCobat,
name="Current Capacity",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
state_class=None,
device_class=SensorDeviceClass.ENERGY,
entity_category=EntityCategory.DIAGNOSTIC
)
]

Expand Down Expand Up @@ -255,7 +278,7 @@
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),AlphaESSSensorDescription(
), AlphaESSSensorDescription(
key=AlphaESSNames.GridIOTotal,
name="Instantaneous Grid I/O Total",
native_unit_of_measurement=UnitOfPower.WATT,
Expand All @@ -270,18 +293,21 @@
), AlphaESSSensorDescription(
key=AlphaESSNames.Income,
name="Total Income",
icon="mdi:cash-multiple",
native_unit_of_measurement=CURRENCY_DOLLAR,
device_class=SensorDeviceClass.MONETARY,
state_class=None,
), AlphaESSSensorDescription(
key=AlphaESSNames.SelfConsumption,
name="Self Consumption",
icon="mdi:percent",
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.POWER_FACTOR,
state_class=None,
), AlphaESSSensorDescription(
key=AlphaESSNames.SelfSufficiency,
name="Self Sufficiency",
icon="mdi:percent",
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.POWER_FACTOR,
state_class=None,
Expand All @@ -290,5 +316,26 @@
name="EMS Status",
device_class=SensorDeviceClass.ENUM,
state_class=None,
entity_category=EntityCategory.DIAGNOSTIC
), AlphaESSSensorDescription(
key=AlphaESSNames.usCapacity,
name="Maximum Battery Capacity",
native_unit_of_measurement=PERCENTAGE,
state_class=None,
entity_category=EntityCategory.DIAGNOSTIC
), AlphaESSSensorDescription(
key=AlphaESSNames.cobat,
name="Installed Capacity",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
state_class=None,
device_class=SensorDeviceClass.ENERGY,
entity_category=EntityCategory.DIAGNOSTIC
), AlphaESSSensorDescription(
key=AlphaESSNames.surplusCobat,
name="Current Capacity",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
state_class=None,
device_class=SensorDeviceClass.ENERGY,
entity_category=EntityCategory.DIAGNOSTIC
)
]
]
Loading