diff --git a/custom_components/greenely/__init__.py b/custom_components/greenely/__init__.py index 00be29d..ca6069b 100644 --- a/custom_components/greenely/__init__.py +++ b/custom_components/greenely/__init__.py @@ -36,9 +36,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: GreenelyConfigEntry) -> entry.async_on_unload(entry.add_update_listener(async_update_options)) - if api.check_auth(): + if await hass.async_add_executor_job(api.check_auth): facilityId = ( - api.get_facility_id() + await hass.async_add_executor_job(api.get_facility_id) if entry.data.get(GREENELY_FACILITY_ID, "") == "" else entry.data[GREENELY_FACILITY_ID] ) diff --git a/custom_components/greenely/config_flow.py b/custom_components/greenely/config_flow.py index 1c8c4f4..b4b6cf9 100644 --- a/custom_components/greenely/config_flow.py +++ b/custom_components/greenely/config_flow.py @@ -48,17 +48,18 @@ class Greenelyhub: """Class to authenticate with the host.""" - def __init__(self, email: str, password: str): + def __init__(self, hass: HomeAssistant, email: str, password: str): + self.hass = hass self.email = email self.password = password self.api = GreenelyApi(self.email, self.password) async def authenticate(self) -> bool: """Test if we can authenticate with the host.""" - return self.api.check_auth() + return await self.hass.async_add_executor_job(self.api.check_auth) async def get_facility_id(self) -> int: - return int(self.api.get_facility_id()) + return int(await self.hass.async_add_executor_job(self.api.get_facility_id)) async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]: @@ -67,7 +68,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user. """ - hub = Greenelyhub(data[CONF_EMAIL], data[CONF_PASSWORD]) + hub = Greenelyhub(hass, data[CONF_EMAIL], data[CONF_PASSWORD]) if not await hub.authenticate(): raise InvalidAuth diff --git a/custom_components/greenely/services.py b/custom_components/greenely/services.py index 2824691..518006d 100644 --- a/custom_components/greenely/services.py +++ b/custom_components/greenely/services.py @@ -30,7 +30,7 @@ async def async_fetch_facilities(call: ServiceCall): password = call.data[CONF_PASSWORD] api = GreenelyApi(email, password) - if not api.check_auth(): + if not await hass.async_add_executor_job(api.check_auth): await hass.services.async_call( NOTIFY_DOMAIN, "persistent_notification", @@ -39,7 +39,7 @@ async def async_fetch_facilities(call: ServiceCall): ) else: - facilityIds = api.get_facility_ids() + facilityIds = await hass.async_add_executor_job(api.get_facility_ids) _LOGGER.info("Facilities fetched successfully") facilityIdsOutput = []