Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sensor, Make Sending Check Optional, Code Cleanup #46

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address corrections in related PRs
Address corrections in PR #42, #43, #44
Snuffy2 committed Oct 9, 2023
commit 0d407df6ed69145025107c5582a5d3d986282bde
13 changes: 5 additions & 8 deletions custom_components/healthchecksio/__init__.py
Original file line number Diff line number Diff line change
@@ -116,8 +116,7 @@ async def async_unload_entry(
curr_plat,
)
if unload_ok:
hass.data[DOMAIN_DATA].pop(DATA_CLIENT, None)
hass.data[DOMAIN_DATA].pop(DATA_DATA, None)
hass.data.pop(DOMAIN_DATA, None)
_LOGGER.info("Successfully removed the HealthChecks.io integration")

return unload_ok
@@ -166,12 +165,10 @@ async def update_data(self):
else:
_LOGGER.debug("Send Check is not defined")
try:
async with session.get(
f"{self.site_root}/api/v1/checks/",
headers=headers,
timeout=timeout10,
) as data:
self.hass.data[DOMAIN_DATA][DATA_DATA] = await data.json()
data = await session.get(
f"{self.site_root}/api/v1/checks/", headers=headers, timeout=timeout10
)
self.hass.data[DOMAIN_DATA][DATA_DATA] = await data.json()
except (aiohttp.ClientError, asyncio.TimeoutError) as error:
_LOGGER.error(f"Could Not Update Data: {error}")
except (ValueError, json.decoder.JSONDecodeError) as error:
17 changes: 7 additions & 10 deletions custom_components/healthchecksio/config_flow.py
Original file line number Diff line number Diff line change
@@ -64,25 +64,22 @@ async def _test_credentials(
else:
_LOGGER.debug("Send Check is not defined")
try:
async with session.get(
f"{site_root}/api/v1/checks/",
headers=headers,
timeout=timeout10,
) as data:
hass.data[DOMAIN_DATA] = {"data": await data.json()}
data = await session.get(
f"{site_root}/api/v1/checks/", headers=headers, timeout=timeout10
)
hass.data[DOMAIN_DATA] = {"data": await data.json()}
except (aiohttp.ClientError, asyncio.TimeoutError) as error:
_LOGGER.error(f"Could Not Update Data: {error}")
return False
except (ValueError, json.decoder.JSONDecodeError) as error:
_LOGGER.error(f"Data JSON Decode Error: {error}")
return False
else:
if data.ok:
_LOGGER.debug(f"Get Data HTTP Status Code: {data.status}")
return True
else:
if not data.ok:
_LOGGER.error(f"Error: Get Data HTTP Status Code: {data.status}")
return False
_LOGGER.debug(f"Get Data HTTP Status Code: {data.status}")
return True


class HealchecksioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):