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

Allow readonly key #64

Merged
merged 1 commit into from
Jul 23, 2024
Merged
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ This integration will send an update to it every `5` minutes.

The API key to your account.
You can find it under the "Settings" tab in your project.
This should **not** be the "Read only" key.

## For self-hosted instances

Expand Down
16 changes: 9 additions & 7 deletions custom_components/healthchecksio/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
)
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from custom_components.healthchecksio import LOGGER

from .const import ATTRIBUTION, DOMAIN

if TYPE_CHECKING:
Expand All @@ -22,12 +20,12 @@

async def async_setup_entry(hass, config_entry, async_add_devices):
"""Setup sensor platform."""
# Send update "signal" to the component
coordinator: HealthchecksioDataUpdateCoordinator = config_entry.runtime_data
async_add_devices(
HealthchecksioBinarySensor(
hass=hass,
ping_url=check.get("ping_url"),
unique_key=check.get("unique_key"),
coordinator=coordinator,
)
for check in coordinator.data.get("checks", [])
Expand All @@ -47,13 +45,16 @@ def __init__(
*,
hass: HomeAssistant,
coordinator: HealthchecksioDataUpdateCoordinator,
ping_url: str,
ping_url: str | None = None,
unique_key: str | None = None,
):
super().__init__(coordinator)
self.hass = hass
self._ping_url = ping_url
self._unique_key = unique_key

self._attr_unique_id = ping_url.split("/")[-1] if ping_url else unique_key

self._attr_unique_id = ping_url.split("/")[-1]
self._attr_device_info = {
"identifiers": {(DOMAIN, self.coordinator.config_entry.entry_id)},
"name": "Healthchecks.io",
Expand All @@ -63,7 +64,9 @@ def __init__(
def get_check(self) -> dict[str, Any]:
"""Get check data."""
for check in self.coordinator.data.get("checks", []):
if self._ping_url == check.get("ping_url"):
if self._ping_url and self._ping_url == check.get("ping_url"):
return check
if self._unique_key and self._unique_key == check.get("unique_key"):
return check
return {}

Expand All @@ -77,7 +80,6 @@ def name(self):
def is_on(self):
"""Return true if the binary_sensor is on."""
check = self.get_check()
LOGGER.debug("Check: %s", check)
return check.get("status") != "down"

@property
Expand Down