diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fb2b49a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +/.idea diff --git a/custom_components/alphaess/coordinator.py b/custom_components/alphaess/coordinator.py index 734d777..3287262 100644 --- a/custom_components/alphaess/coordinator.py +++ b/custom_components/alphaess/coordinator.py @@ -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 @@ -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", {}) diff --git a/custom_components/alphaess/enums.py b/custom_components/alphaess/enums.py index 0992442..30f12ce 100644 --- a/custom_components/alphaess/enums.py +++ b/custom_components/alphaess/enums.py @@ -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" diff --git a/custom_components/alphaess/sensor.py b/custom_components/alphaess/sensor.py index f61e68d..2874b9a 100644 --- a/custom_components/alphaess/sensor.py +++ b/custom_components/alphaess/sensor.py @@ -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}") @@ -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 @@ -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.""" @@ -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 diff --git a/custom_components/alphaess/sensorlist.py b/custom_components/alphaess/sensorlist.py index 2b7d616..79b774c 100644 --- a/custom_components/alphaess/sensorlist.py +++ b/custom_components/alphaess/sensorlist.py @@ -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, @@ -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, @@ -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 ) ] @@ -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, @@ -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, @@ -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 ) -] +] \ No newline at end of file