Skip to content

Commit

Permalink
Cleanup of aioxcom start code
Browse files Browse the repository at this point in the history
  • Loading branch information
ankohanse committed Sep 4, 2024
1 parent 323a877 commit fdfb2ea
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 26 deletions.
4 changes: 1 addition & 3 deletions custom_components/studer_xcom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b

# Get our Coordinator instance for this port and start it
coordinator: StuderCoordinator = StuderCoordinatorFactory.create(hass, config_entry)
await coordinator.start()

if not await coordinator.wait_until_connected():
if not await coordinator.start():
raise ConfigEntryNotReady(f"Timout while waiting for Studer Xcom client to connect to our port {port}.")

# Fetch initial data so we have data when entities subscribe
Expand Down
5 changes: 2 additions & 3 deletions custom_components/studer_xcom/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ async def _async_xcom_connect(self):
_LOGGER.info("Discover Xcom connection")
self._coordinator = StuderCoordinatorFactory.create_temp(self._voltage, self._port)

await self._coordinator.start()
if not await self._coordinator.wait_until_connected(30):
if not await self._coordinator.start(30):
self._errors[CONF_PORT] = f"Xcom client did not connect to the specified port"
return

Expand Down Expand Up @@ -252,7 +251,7 @@ async def _async_xcom_devices(self):
# - the device does not support the param (INVALID_DATA), used to distinguish BSP from BMS
success = await self._async_xcom_device_test(nr, family.idForNr, device_addr)
if success:
device_code = family.get_code(device_addr)
device_code = family.getCode(device_addr)
_LOGGER.info(f"Found device {device_code} via {nr}:{device_addr}")

# In reconfigure, did we already have a deviceConfig for this device?
Expand Down
21 changes: 2 additions & 19 deletions custom_components/studer_xcom/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,31 +229,17 @@ def _get_data(self):
return self._entity_map


async def start(self):
async def start(self) -> bool:
self._modified_map = await self._async_fetch_from_cache(MODIFIED_PARAMS)
self._modified_map_ts = datetime.now()

await self._api.start()
return await self._api.start()


async def stop(self):
await self._api.stop()


async def wait_until_connected(self, timeout=20) -> bool:
try:
for i in range(timeout):
if self._api.connected:
return True

await asyncio.sleep(1)

except Exception as e:
_LOGGER.warning(f"Exception while checking connection to Xcom client: {e}")

return False


def is_connected(self) -> bool:
return self._api.connected

Expand Down Expand Up @@ -312,9 +298,6 @@ async def _async_update_data(self):
_LOGGER.debug(f"Update data")

try:
if not await self.wait_until_connected():
return

# Request values for each configured param or infos number (datapoints).
# Note that a single (broadcasted) request can result in multiple reponses received
# (for instance in systems with more than one inverter)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/studer_xcom/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/ankohanse/hass-studer-xcom/issues",
"loggers": ["custom_components.studer_xcom"],
"requirements": ["aioxcom>=1.0.0"],
"requirements": ["aioxcom>=1.0.1"],
"version": "2024.09.1"
}

0 comments on commit fdfb2ea

Please sign in to comment.