Skip to content

Commit

Permalink
Don't create task in thread (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 authored May 18, 2024
1 parent df0900d commit bcfd7ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 4 additions & 4 deletions custom_components/sandman_doppler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""The Sandman Doppler integration."""

from __future__ import annotations

import asyncio
from datetime import timedelta
import functools
import logging
from typing import Any

Expand Down Expand Up @@ -45,7 +47,7 @@
]


async def _get_devices(client: Doppler) -> None:
async def _get_devices(client: DopplerClient) -> None:
"""Helper function to get devices from cloud."""
try:
await client.get_devices()
Expand Down Expand Up @@ -121,9 +123,7 @@ def async_on_device_removed(doppler: Doppler) -> None:
# and remove device listeners if the list changes
entry.async_on_unload(
async_track_time_interval(
hass,
lambda _: hass.async_create_task(_get_devices(client)),
timedelta(minutes=5),
hass, functools.partial(_get_devices, client), timedelta(minutes=5)
)
)

Expand Down
9 changes: 3 additions & 6 deletions custom_components/sandman_doppler/device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

import voluptuous as vol

from homeassistant.components.automation import (
AutomationActionType,
AutomationTriggerInfo,
)
from homeassistant.components.device_automation import DEVICE_TRIGGER_BASE_SCHEMA
from homeassistant.components.homeassistant.triggers import event as event_trigger
from homeassistant.const import (
Expand All @@ -20,6 +16,7 @@
)
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType

from .const import ATTR_BUTTON, CONF_SUBTYPE, DOMAIN, EVENT_BUTTON_PRESSED
Expand Down Expand Up @@ -71,8 +68,8 @@ async def async_get_triggers(
async def async_attach_trigger(
hass: HomeAssistant,
config: ConfigType,
action: AutomationActionType,
automation_info: AutomationTriggerInfo,
action: TriggerActionType,
automation_info: TriggerInfo,
) -> CALLBACK_TYPE:
"""Attach a trigger."""

Expand Down

0 comments on commit bcfd7ac

Please sign in to comment.