Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions custom_components/greenely/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Expand Down
9 changes: 5 additions & 4 deletions custom_components/greenely/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/greenely/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = []
Expand Down