Skip to content

Commit

Permalink
Added name/host from config to ABBPowerOneFimerAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdelprete committed Feb 6, 2024
1 parent 7f815c3 commit eafb8ff
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
76 changes: 38 additions & 38 deletions custom_components/abb_powerone_pvi_sunspec/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,50 @@ def __init__(
self._sensors = []
self.data = {}
# Initialize ModBus data structure before first read
self.init_modbus_data()
self.data["accurrent"] = 1
self.data["accurrenta"] = 1
self.data["accurrentb"] = 1
self.data["accurrentc"] = 1
self.data["acvoltageab"] = 1
self.data["acvoltagebc"] = 1
self.data["acvoltageca"] = 1
self.data["acvoltagean"] = 1
self.data["acvoltagebn"] = 1
self.data["acvoltagecn"] = 1
self.data["acpower"] = 1
self.data["acfreq"] = 1
self.data["comm_options"] = 1
self.data["comm_manufact"] = ""
self.data["comm_model"] = ""
self.data["comm_version"] = ""
self.data["comm_sernum"] = ""
self.data["mppt_nr"] = 1
self.data["dccurr"] = 1
self.data["dcvolt"] = 1
self.data["dcpower"] = 1
self.data["dc1curr"] = 1
self.data["dc1volt"] = 1
self.data["dc1power"] = 1
self.data["dc2curr"] = 1
self.data["dc2volt"] = 1
self.data["dc2power"] = 1
self.data["invtype"] = ""
self.data["status"] = ""
self.data["statusvendor"] = ""
self.data["totalenergy"] = 1
self.data["tempcab"] = 1
self.data["tempoth"] = 1

@property
def name(self):
"""Return the device name."""
return self._name

@property
def host(self):
"""Return the device name."""
return self._host

def check_port(self) -> bool:
"""Check if port is available."""
with self._lock:
Expand Down Expand Up @@ -146,43 +183,6 @@ def calculate_value(self, value, scalefactor):
"""Apply Scale Factor."""
return value * 10**scalefactor

def init_modbus_data(self):
"""Initialize Dataset."""
self.data["accurrent"] = 1
self.data["accurrenta"] = 1
self.data["accurrentb"] = 1
self.data["accurrentc"] = 1
self.data["acvoltageab"] = 1
self.data["acvoltagebc"] = 1
self.data["acvoltageca"] = 1
self.data["acvoltagean"] = 1
self.data["acvoltagebn"] = 1
self.data["acvoltagecn"] = 1
self.data["acpower"] = 1
self.data["acfreq"] = 1
self.data["comm_options"] = 1
self.data["comm_manufact"] = ""
self.data["comm_model"] = ""
self.data["comm_version"] = ""
self.data["comm_sernum"] = ""
self.data["mppt_nr"] = 1
self.data["dccurr"] = 1
self.data["dcvolt"] = 1
self.data["dcpower"] = 1
self.data["dc1curr"] = 1
self.data["dc1volt"] = 1
self.data["dc1power"] = 1
self.data["dc2curr"] = 1
self.data["dc2volt"] = 1
self.data["dc2power"] = 1
self.data["invtype"] = ""
self.data["status"] = ""
self.data["statusvendor"] = ""
self.data["totalenergy"] = 1
self.data["tempcab"] = 1
self.data["tempoth"] = 1
return True

async def async_get_data(self):
"""Read Data Function."""

Expand Down
10 changes: 7 additions & 3 deletions custom_components/abb_powerone_pvi_sunspec/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import (
CONF_HOST,
CONF_NAME,
DATA,
DOMAIN,
Expand Down Expand Up @@ -101,8 +100,13 @@ def __init__(self, coordinator, config_entry, sensor_data):
self._icon = sensor_data["icon"]
self._device_class = sensor_data["device_class"]
self._state_class = sensor_data["state_class"]
self._device_name = config_entry.data.get(CONF_NAME)
self._device_host = config_entry.data.get(CONF_HOST)
# self._device_name = config_entry.data.get(CONF_NAME)
# self._device_host = config_entry.data.get(CONF_HOST)
self._device_name = self.coordinator.api.name
self._device_host = self.coordinator.api.host
_LOGGER.debug(
f"Sensor - DevName: {self._device_name} DevHost: {self._device_host}"
)
self._device_model = self.coordinator.api.data["comm_model"]
self._device_manufact = self.coordinator.api.data["comm_manufact"]
self._device_sn = self.coordinator.api.data["comm_sernum"]
Expand Down

0 comments on commit eafb8ff

Please sign in to comment.