Skip to content

Commit

Permalink
Blocking call Fix and Import Store Directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Sian-Lee-SA committed Jun 5, 2024
1 parent a6ab968 commit 3d28e77
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 0 additions & 1 deletion custom_components/switch_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ async def async_setup_entry( hass, config_entry ):

async def async_migrate( hass, in_dev ):
store = hass.data[DOMAIN][CONF_STORE]

version_update = not store.compare_version( VERSION )
if in_dev or version_update or not await check_blueprints_folder_exists( hass ):
LOGGER.debug('Migrating blueprints')
Expand Down
25 changes: 16 additions & 9 deletions custom_components/switch_manager/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

VERSION = MANIFEST['version']


async def check_blueprints_folder_exists( hass ):
dest_folder = pathlib.Path(hass.config.path(BLUEPRINTS_FOLDER, DOMAIN))
return os.path.exists( dest_folder )
Expand All @@ -32,19 +31,27 @@ async def deploy_blueprints( hass ):

component_blueprints_path = os.path.join( COMPONENT_PATH, 'blueprints' )
files = os.listdir(component_blueprints_path)
for file in files:
if os.path.isfile( os.path.join( component_blueprints_path, file )):
shutil.copy(
os.path.join( component_blueprints_path, file ),
dest_folder
)

def load_blueprints( hass ):
def doFiles():
for file in files:
if os.path.isfile( os.path.join( component_blueprints_path, file )):
shutil.copy(
os.path.join( component_blueprints_path, file ),
dest_folder
)

await hass.async_add_executor_job(doFiles)

async def load_blueprints( hass ):
folder = pathlib.Path(hass.config.path(BLUEPRINTS_FOLDER, DOMAIN))
results = [];
for f in _find_files(folder, "*.yaml"):
try:
data = load_yaml(f)
data = await hass.loop.run_in_executor(
None,
load_yaml,
f
)
except HomeAssistantError as ex:
LOGGER.error(str(ex))
continue
Expand Down
2 changes: 1 addition & 1 deletion custom_components/switch_manager/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/Sian-Lee-SA/Home-Assistant-Switch-Manager/issues",
"requirements": [],
"version": "1.3.3"
"version": "1.3.4"
}
1 change: 1 addition & 0 deletions custom_components/switch_manager/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SwitchManagerStore:

def __init__(self, hass):
self.store = Store(hass, STORAGE_VERSION, STORAGE_ID)

self.data = None
self.dirty = False

Expand Down

0 comments on commit 3d28e77

Please sign in to comment.