-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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 separate data coordinators for AccuWeather observation and forecast #115628
Use separate data coordinators for AccuWeather observation and forecast #115628
Conversation
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class AccuWeatherDataUpdateCoordinator(TimestampDataUpdateCoordinator[Any]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a TimestampDataUpdateCoordinator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a DataUpdateCoordinator
which keeps track of the last successful update:
core/homeassistant/helpers/update_coordinator.py
Lines 453 to 463 in c7e6f36
class TimestampDataUpdateCoordinator(DataUpdateCoordinator[_DataT]): | |
"""DataUpdateCoordinator which keeps track of the last successful update.""" | |
last_update_success_time: datetime | None = None | |
@callback | |
def _async_refresh_finished(self) -> None: | |
"""Handle when a refresh has finished.""" | |
if self.last_update_success: | |
self.last_update_success_time = utcnow() | |
WeaterEntity
uses it:
core/homeassistant/components/weather/__init__.py
Lines 147 to 155 in c7e6f36
_DailyForecastUpdateCoordinatorT = TypeVar( | |
"_DailyForecastUpdateCoordinatorT", bound="TimestampDataUpdateCoordinator[Any]" | |
) | |
_HourlyForecastUpdateCoordinatorT = TypeVar( | |
"_HourlyForecastUpdateCoordinatorT", bound="TimestampDataUpdateCoordinator[Any]" | |
) | |
_TwiceDailyForecastUpdateCoordinatorT = TypeVar( | |
"_TwiceDailyForecastUpdateCoordinatorT", bound="TimestampDataUpdateCoordinator[Any]" | |
) |
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class AccuWeatherDataUpdateCoordinator(TimestampDataUpdateCoordinator[Any]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a generic so we add the return type annotation?
for description in FORECAST_SENSOR_TYPES: | ||
# Some air quality/allergy sensors are only available for certain | ||
# locations. | ||
if description.key not in forecast_daily_coordinator.data[description.day]: | ||
continue | ||
sensors.append(AccuWeatherSensor(forecast_daily_coordinator, description)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be a generator expression
class AccuWeatherEntity( | ||
SingleCoordinatorWeatherEntity[AccuWeatherDataUpdateCoordinator] | ||
): | ||
class AccuWeatherEntity(CoordinatorWeatherEntity): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can retain this coordinator type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand, why do you want to use SingleCoordinatorWeatherEntity
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed the CoordinatorWeatherEntity
also takes in a coordinator in the type CoordinatorWeatherEntity[AccuWeatherDataUpdateCoordinator]
(but then the new coordinator)
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
ba30bac
to
a9721b5
Compare
@@ -42,12 +49,12 @@ | |||
) | |||
|
|||
|
|||
async def test_sensor_without_forecast( | |||
async def test_sensor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Snapshots would be a nice improvment for this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you wish 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I mean that as a separate PR, but this also works
Thanks @joostlek |
Breaking change
Proposed change
This PR:
The observation (current conditions) data update interval remains unchanged (every 40 minutes). Forecast data is updated every 6 hours. With this configuration, the integration performs 40 requests per day. This gives us 10 requests left for HA restarts or reload config entry (free AccuWeather accounts allow you to make 50 requests per day).
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: