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

Use async_at_started in Netatmo #100996

Merged
merged 2 commits into from
Oct 2, 2023
Merged
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
21 changes: 6 additions & 15 deletions homeassistant/components/netatmo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""The Netatmo integration."""
from __future__ import annotations

from datetime import datetime
from http import HTTPStatus
import logging
import secrets
from typing import Any

import aiohttp
import pyatmo
Expand All @@ -26,16 +26,9 @@
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_WEBHOOK_ID,
EVENT_HOMEASSISTANT_STARTED,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import (
DOMAIN as HOMEASSISTANT_DOMAIN,
CoreState,
Event,
HomeAssistant,
ServiceCall,
)
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import (
aiohttp_client,
Expand All @@ -45,6 +38,7 @@
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.start import async_at_started
from homeassistant.helpers.typing import ConfigType

from . import api
Expand Down Expand Up @@ -185,7 +179,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await data_handler.async_setup()

async def unregister_webhook(
call_or_event_or_dt: ServiceCall | Event | datetime | None,
_: Any,
) -> None:
if CONF_WEBHOOK_ID not in entry.data:
return
Expand All @@ -204,7 +198,7 @@ async def unregister_webhook(
)

async def register_webhook(
call_or_event_or_dt: ServiceCall | Event | datetime | None,
_: Any,
) -> None:
if CONF_WEBHOOK_ID not in entry.data:
data = {**entry.data, CONF_WEBHOOK_ID: secrets.token_hex()}
Expand Down Expand Up @@ -254,11 +248,8 @@ async def manage_cloudhook(state: cloud.CloudConnectionState) -> None:
if cloud.async_is_connected(hass):
await register_webhook(None)
cloud.async_listen_connection_change(hass, manage_cloudhook)

elif hass.state == CoreState.running:
await register_webhook(None)
else:
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, register_webhook)
async_at_started(hass, register_webhook)

hass.services.async_register(DOMAIN, "register_webhook", register_webhook)
hass.services.async_register(DOMAIN, "unregister_webhook", unregister_webhook)
Expand Down
Loading