Skip to content

Commit

Permalink
Allow readonly key
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Jul 23, 2024
1 parent 77a7fe3 commit bc9ebda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
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

0 comments on commit bc9ebda

Please sign in to comment.