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

Fix blocking call inside the event loop #89

Merged
merged 2 commits into from
Jun 18, 2024
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
13 changes: 6 additions & 7 deletions custom_components/rte_ecowatt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import urllib.parse
import logging
from datetime import timedelta, datetime
from datetime import datetime, timedelta, tzinfo
from zoneinfo import ZoneInfo
from typing import Any, Dict, Optional, Tuple
from dateutil import tz
Expand All @@ -27,6 +27,7 @@
from homeassistant.helpers.httpx_client import get_async_client
from homeassistant.components.sensor import RestoreSensor
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
from homeassistant.util import dt as dt_util

from .const import (
CONF_CLIENT_ID,
Expand Down Expand Up @@ -133,9 +134,8 @@ async def async_oauth_client(self):
self.token = client.token
return client

def _timezone(self):
timezone = self.hass.config.as_dict()["time_zone"]
return tz.gettz(timezone)
def _timezone(self) -> tzinfo:
return dt_util.get_default_time_zone()

def skip_refresh(self) -> Optional[str]:
"""
Expand Down Expand Up @@ -407,9 +407,8 @@ def __init__(
}
self._attr_extra_state_attributes["options"] = list(self.options.values()) + ["Coupure d'électricité en cours"]

def _timezone(self):
timezone = self.hass.config.as_dict()["time_zone"]
return tz.gettz(timezone)
def _timezone(self) -> tzinfo:
return dt_util.get_default_time_zone()

def _find_ecowatt_level(self) -> Optional[int]:
raise NotImplementedError()
Expand Down