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

A few experiements for anitiflicker. #166

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 16 additions & 5 deletions custom_components/ha_blueair/blueair_update_coordinator.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
"""Blueair device object."""
from __future__ import annotations
import logging
from datetime import timedelta

from abc import ABC, abstractmethod
import asyncio
from datetime import timedelta
import logging

from blueair_api import Device as BlueAirApiDevice, DeviceAws as BlueAirAwsDevice

from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, REQUEST_REFRESH_DEFAULT_COOLDOWN, Debouncer
from homeassistant.helpers.update_coordinator import (
REQUEST_REFRESH_DEFAULT_COOLDOWN,
DataUpdateCoordinator,
Debouncer)

from .const import DOMAIN
from .const import DOMAIN, DEVICE_REFRESH_WAIT_SECONDS

_LOGGER = logging.getLogger(__name__)

Expand All @@ -35,10 +40,16 @@ def __init__(
_LOGGER,
name=f"{DOMAIN}-{self.blueair_api_device.name}",
update_interval=timedelta(minutes=5),
update_method=self.blueair_api_device.refresh,
update_method=self.wait_and_update,
request_refresh_debouncer=request_refresh_debouncer
)

async def wait_and_update(self):
"""Wait and update to account for Blueair API latency."""
_LOGGER.error("wait_and_update called")
# await asyncio.sleep(DEVICE_REFRESH_WAIT_SECONDS)
await self.blueair_api_device.refresh()

@property
def id(self) -> str:
"""Return Blueair device id."""
Expand Down
3 changes: 3 additions & 0 deletions custom_components/ha_blueair/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@

DEFAULT_FAN_SPEED_PERCENTAGE = 50
FILTER_EXPIRED_THRESHOLD = 95

# Wait time to account for latency in Blueair server side state update.
DEVICE_REFRESH_WAIT_SECONDS = 5
2 changes: 2 additions & 0 deletions custom_components/ha_blueair/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def __init__(
self._attr_unique_id = f"{coordinator.id}_{entity_type}"

self.coordinator: BlueairUpdateCoordinator = coordinator
self.coordinator.blueair_api_device.register_callback(
self.schedule_update_ha_state)

@property
def device_info(self) -> DeviceInfo:
Expand Down
Loading