Skip to content

Commit

Permalink
Merge pull request #418 from trizmark/main
Browse files Browse the repository at this point in the history
Add libbi support
  • Loading branch information
CJNE committed Oct 4, 2023
2 parents 33de175 + f7275d2 commit 2aac276
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/myenergi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
NAME = "myenergi"
DOMAIN = "myenergi"
DOMAIN_DATA = f"{DOMAIN}_data"
VERSION = "0.0.23"
VERSION = "0.0.24"

ATTRIBUTION = "Data provided by myenergi"
ISSUE_URL = "https://github.com/CJNE/ha-myenergi/issues"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/myenergi/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"documentation": "https://github.com/cjne/ha-myenergi",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/cjne/ha-myenergi/issues",
"requirements": ["pymyenergi==0.0.27"],
"version": "0.0.23"
"requirements": ["pymyenergi==0.0.29"],
"version": "0.0.24"
}
2 changes: 2 additions & 0 deletions custom_components/myenergi/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ async def async_setup_entry(hass, entry, async_add_devices):
elif device.kind == "eddi":
devices.append(HeaterPriorityNumber(coordinator, device, entry))
devices.append(DevicePriorityNumber(coordinator, device, entry))
elif device.kind == "libbi":
devices.append(DevicePriorityNumber(coordinator, device, entry))
async_add_devices(devices)


Expand Down
41 changes: 41 additions & 0 deletions custom_components/myenergi/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from homeassistant.helpers import entity_platform
from pymyenergi.eddi import EDDI_MODES
from pymyenergi.zappi import CHARGE_MODES
from pymyenergi.libbi import LIBBI_MODES
from pymyenergi.libbi import LIBBI_MODE_NAMES
from pymyenergi.libbi import MODE_STOPPED
from pymyenergi.libbi import MODE_NORMAL

from .const import DOMAIN
from .entity import MyenergiEntity
Expand Down Expand Up @@ -60,6 +64,8 @@ async def async_setup_entry(hass, entry, async_add_devices):
"start_eddi_boost",
)
devices.append(EddiOperatingModeSelect(coordinator, device, entry))
elif device.kind == "libbi":
devices.append(LibbiOperatingModeSelect(coordinator, device, entry))
async_add_devices(devices)


Expand Down Expand Up @@ -132,3 +138,38 @@ async def async_select_option(self, option: str) -> None:
@property
def options(self):
return CHARGE_MODES[1:]


class LibbiOperatingModeSelect(MyenergiEntity, SelectEntity):
"""myenergi Sensor class."""

def __init__(self, coordinator, device, config_entry):
super().__init__(coordinator, device, config_entry)

@property
def unique_id(self):
"""Return a unique ID to use for this entity."""
return (
f"{self.config_entry.entry_id}-{self.device.serial_number}-operating_mode"
)

@property
def name(self):
"""Return the name of the sensor."""
return f"myenergi {self.device.name} Operating Mode"

@property
def current_option(self):
"""Return the state of the sensor."""
if self.device.local_mode == LIBBI_MODE_NAMES[MODE_STOPPED]:
return LIBBI_MODES[MODE_STOPPED]
return LIBBI_MODES[MODE_NORMAL]

async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
await self.device.set_operating_mode(option)
self.async_schedule_update_ha_state()

@property
def options(self):
return LIBBI_MODES
177 changes: 176 additions & 1 deletion custom_components/myenergi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from homeassistant.const import DEVICE_CLASS_POWER
from homeassistant.const import DEVICE_CLASS_TEMPERATURE
from homeassistant.const import DEVICE_CLASS_VOLTAGE
from homeassistant.const import DEVICE_CLASS_BATTERY
from homeassistant.const import ELECTRIC_POTENTIAL_VOLT
from homeassistant.const import ENERGY_KILO_WATT_HOUR
from homeassistant.const import FREQUENCY_HERTZ
Expand All @@ -20,6 +21,7 @@
from pymyenergi import EDDI
from pymyenergi import HARVI
from pymyenergi import ZAPPI
from pymyenergi import LIBBI

from .const import DOMAIN
from .entity import MyenergiEntity
Expand All @@ -29,6 +31,8 @@

ICON_VOLT = "mdi:lightning-bolt"
ICON_FREQ = "mdi:sine-wave"
ICON_POWER = "mdi:flash"
ICON_HOME_BATTERY = "mdi:home-battery"


def create_meta(
Expand Down Expand Up @@ -486,6 +490,177 @@ async def async_setup_entry(hass, entry, async_add_devices):
),
)
)
elif device.kind == LIBBI:
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"SoC",
"state_of_charge",
DEVICE_CLASS_BATTERY,
PERCENTAGE,
),
)
)
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"Voltage",
"supply_voltage",
DEVICE_CLASS_VOLTAGE,
ELECTRIC_POTENTIAL_VOLT,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_VOLT,
STATE_CLASS_MEASUREMENT,
),
)
)
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"Frequency",
"supply_frequency",
None,
FREQUENCY_HERTZ,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_FREQ,
STATE_CLASS_MEASUREMENT,
),
)
)
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"Inverter size",
"inverter_size",
None,
ENERGY_KILO_WATT_HOUR,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_POWER,
),
)
)
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"Battery size",
"battery_size",
None,
ENERGY_KILO_WATT_HOUR,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_POWER,
)
)
)
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"Status",
"status",
None,
None,
None,
ICON_HOME_BATTERY,
)
)
)
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"Grid import today",
"grid_import",
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
None,
None,
STATE_CLASS_TOTAL_INCREASING,
)
)
)
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"Grid export today",
"grid_export",
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
None,
None,
STATE_CLASS_TOTAL_INCREASING,
)
)
)
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"Battery charge today",
"battery_charge",
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
None,
None,
STATE_CLASS_TOTAL_INCREASING,
)
)
)
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"Battery discharge today",
"battery_discharge",
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
None,
None,
STATE_CLASS_TOTAL_INCREASING,
)
)
)
sensors.append(
MyenergiSensor(
coordinator,
device,
entry,
create_meta(
f"Solar generation today",
"generated",
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
None,
None,
STATE_CLASS_TOTAL_INCREASING,
)
)
)
async_add_devices(sensors)


Expand All @@ -498,7 +673,7 @@ def __init__(self, coordinator, config_entry, meta):
@property
def unique_id(self):
"""Return a unique ID to use for this entity."""
return f"{self.config_entry.entry_id}-{self.coordinator.client.serial_number}-{self.meta['prop_name']}"
return f"{self.config_entry.entry_id}-hub-{self.coordinator.client.serial_number}-{self.meta['prop_name']}"

@property
def name(self):
Expand Down

0 comments on commit 2aac276

Please sign in to comment.