Skip to content

Commit

Permalink
refactor: Conscise loading of inverter profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Jul 26, 2024
1 parent 49163d5 commit 157009a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
git config --global user.name "Continuous Integration"
git config --global user.email "[email protected]"
git commit -m "chore: bump version" custom_components/solarman/manifest.json
git push
git push
4 changes: 4 additions & 0 deletions custom_components/solarman/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import yaml
import asyncio
import aiofiles
Expand All @@ -14,6 +15,9 @@ async def async_execute(x):
loop = asyncio.get_running_loop()
return await loop.run_in_executor(None, x)

async def async_listdir(path, prefix = ""):
return sorted([prefix + f for f in await async_execute(lambda: os.listdir(path)) if os.path.isfile(path + f)]) if os.path.exists(path) else []

def execute_async(x):
loop = asyncio.get_event_loop()
return loop.run_until_complete(x)
Expand Down
4 changes: 1 addition & 3 deletions custom_components/solarman/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ async def step_user_data_process(discovery):
return { CONF_NAME: DEFAULT_NAME, CONF_DISCOVERY: DEFAULT_DISCOVERY, CONF_INVERTER_HOST: await discovery.get_ip(), CONF_INVERTER_SERIAL: await discovery.get_serial(), CONF_INVERTER_PORT: DEFAULT_PORT_INVERTER, CONF_INVERTER_MB_SLAVE_ID: DEFAULT_INVERTER_MB_SLAVE_ID, CONF_LOOKUP_FILE: DEFAULT_LOOKUP_FILE, CONF_BATTERY_NOMINAL_VOLTAGE: DEFAULT_BATTERY_NOMINAL_VOLTAGE, CONF_BATTERY_LIFE_CYCLE_RATING: DEFAULT_BATTERY_LIFE_CYCLE_RATING }

async def step_user_data_schema(hass: HomeAssistant, data: dict[str, Any] = { CONF_NAME: DEFAULT_NAME, CONF_DISCOVERY: DEFAULT_DISCOVERY, CONF_INVERTER_PORT: DEFAULT_PORT_INVERTER, CONF_INVERTER_MB_SLAVE_ID: DEFAULT_INVERTER_MB_SLAVE_ID, CONF_LOOKUP_FILE: DEFAULT_LOOKUP_FILE, CONF_BATTERY_NOMINAL_VOLTAGE: DEFAULT_BATTERY_NOMINAL_VOLTAGE, CONF_BATTERY_LIFE_CYCLE_RATING: DEFAULT_BATTERY_LIFE_CYCLE_RATING }, wname: bool = True) -> vol.Schema:
lookup_files = sorted([f for f in await async_execute(lambda: os.listdir(hass.config.path(LOOKUP_DIRECTORY_PATH))) if os.path.isfile(LOOKUP_DIRECTORY_PATH + f)])
if os.path.exists(hass.config.path(LOOKUP_CUSTOM_DIRECTORY_PATH)):
lookup_files = lookup_files + sorted([f"custom/{f}" for f in await async_execute(lambda: os.listdir(hass.config.path(LOOKUP_CUSTOM_DIRECTORY_PATH))) if os.path.isfile(LOOKUP_CUSTOM_DIRECTORY_PATH + f)])
lookup_files = await async_listdir(hass.config.path(LOOKUP_DIRECTORY_PATH)) + await async_listdir(hass.config.path(LOOKUP_CUSTOM_DIRECTORY_PATH), "custom/")
_LOGGER.debug(f"step_user_data_schema: data: {data}, {LOOKUP_DIRECTORY_PATH}: {lookup_files}")
#STEP_USER_DATA_SCHEMA = vol.Schema({ vol.Required(CONF_NAME, default = data.get(CONF_NAME)): str }, extra = vol.PREVENT_EXTRA) if wname else vol.Schema({}, extra = vol.PREVENT_EXTRA)
#STEP_USER_DATA_SCHEMA = STEP_USER_DATA_SCHEMA.extend(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,6 @@ parameters:

- name: "DC Temperature"
update_interval: 30
disabled:
class: "temperature"
state_class: "measurement"
uom: "°C"
Expand Down

0 comments on commit 157009a

Please sign in to comment.