Thomas Kistler 0dd8ffd1f5
Add a new "Ambient Weather Network" integration (#105779)
* Adding a new "Ambient Weather Network" integration.

* Rebase and update code coverage.

* Addressed some reviewer comments.

* Remove mnemonics and replace with station names.

* Remove climate-utils

* Remove support for virtual stations.

* Rebase

* Address feedback

* Remove redundant errors

* Reviewer feedback

* Add icons.json

* More icons

* Reviewer feedback

* Fix test

* Make sensor tests more robust

* Make coordinator more robust

* Change update coordinator to raise UpdateFailed

* Recover from no station found error

* Dynamically set device name

* Address feedback

* Disable some sensors by default

* Reviewer feedback

* Change from hub to service

* Rebase

* Address reviewer feedback

* Reviewer feedback

* Manually rerun ruff on all files
2024-04-16 09:46:15 +02:00

32 lines
885 B
Python

"""Helper class for the Ambient Weather Network integration."""
from __future__ import annotations
from typing import Any
from .const import (
API_LAST_DATA,
API_STATION_COORDS,
API_STATION_INFO,
API_STATION_LOCATION,
API_STATION_NAME,
API_STATION_TYPE,
)
def get_station_name(station: dict[str, Any]) -> str:
"""Pick a station name.
Station names can be empty, in which case we construct the name from
the location and device type.
"""
if name := station.get(API_STATION_INFO, {}).get(API_STATION_NAME):
return str(name)
location = (
station.get(API_STATION_INFO, {})
.get(API_STATION_COORDS, {})
.get(API_STATION_LOCATION)
)
station_type = station.get(API_LAST_DATA, {}).get(API_STATION_TYPE)
return f"{location}{'' if location is None or station_type is None else ' '}{station_type}"