2019-04-03 15:40:03 +00:00
|
|
|
"""Sensor for the Austrian "Zentralanstalt für Meteorologie und Geodynamik"."""
|
2021-08-23 20:44:03 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
import csv
|
2021-08-23 20:44:03 +00:00
|
|
|
from dataclasses import dataclass
|
2017-11-04 19:04:05 +00:00
|
|
|
from datetime import datetime, timedelta
|
2017-02-24 21:45:46 +00:00
|
|
|
import gzip
|
|
|
|
import json
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
import logging
|
2017-02-24 21:45:46 +00:00
|
|
|
import os
|
2022-01-11 20:26:45 +00:00
|
|
|
from typing import Union
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
2017-11-04 19:04:05 +00:00
|
|
|
from aiohttp.hdrs import USER_AGENT
|
2016-12-06 14:49:59 +00:00
|
|
|
import requests
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2021-12-16 00:17:20 +00:00
|
|
|
from homeassistant.components.sensor import (
|
|
|
|
SensorDeviceClass,
|
|
|
|
SensorEntity,
|
|
|
|
SensorEntityDescription,
|
|
|
|
)
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
from homeassistant.const import (
|
2020-09-15 21:00:26 +00:00
|
|
|
AREA_SQUARE_METERS,
|
2019-12-19 13:00:22 +00:00
|
|
|
ATTR_ATTRIBUTION,
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_LATITUDE,
|
|
|
|
CONF_LONGITUDE,
|
|
|
|
CONF_MONITORED_CONDITIONS,
|
2019-12-09 17:54:54 +00:00
|
|
|
CONF_NAME,
|
2020-04-21 17:45:53 +00:00
|
|
|
DEGREE,
|
2020-04-12 19:44:56 +00:00
|
|
|
LENGTH_METERS,
|
2020-09-05 19:09:14 +00:00
|
|
|
PERCENTAGE,
|
2020-09-19 07:26:08 +00:00
|
|
|
PRESSURE_HPA,
|
2020-02-25 01:52:14 +00:00
|
|
|
SPEED_KILOMETERS_PER_HOUR,
|
2020-04-10 17:17:46 +00:00
|
|
|
TEMP_CELSIUS,
|
2019-07-31 19:25:30 +00:00
|
|
|
__version__,
|
|
|
|
)
|
2022-01-04 09:52:30 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2017-11-04 19:04:05 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2022-01-04 09:52:30 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2021-05-08 05:46:26 +00:00
|
|
|
from homeassistant.util import Throttle, dt as dt_util
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
2017-08-06 13:20:51 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_STATION = "station"
|
|
|
|
ATTR_UPDATED = "updated"
|
2017-11-04 19:04:05 +00:00
|
|
|
ATTRIBUTION = "Data provided by ZAMG"
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_STATION_ID = "station_id"
|
2016-12-06 14:49:59 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DEFAULT_NAME = "zamg"
|
2016-12-06 14:49:59 +00:00
|
|
|
|
2017-08-06 13:20:51 +00:00
|
|
|
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=10)
|
2021-05-08 05:46:26 +00:00
|
|
|
VIENNA_TIME_ZONE = dt_util.get_time_zone("Europe/Vienna")
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
2022-01-11 20:26:45 +00:00
|
|
|
DTypeT = Union[type[int], type[float], type[str]]
|
2021-08-23 20:44:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class ZamgRequiredKeysMixin:
|
|
|
|
"""Mixin for required keys."""
|
|
|
|
|
|
|
|
col_heading: str
|
|
|
|
dtype: DTypeT
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class ZamgSensorEntityDescription(SensorEntityDescription, ZamgRequiredKeysMixin):
|
|
|
|
"""Describes Zamg sensor entity."""
|
|
|
|
|
|
|
|
|
|
|
|
SENSOR_TYPES: tuple[ZamgSensorEntityDescription, ...] = (
|
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="pressure",
|
|
|
|
name="Pressure",
|
|
|
|
native_unit_of_measurement=PRESSURE_HPA,
|
|
|
|
col_heading="LDstat hPa",
|
|
|
|
dtype=float,
|
|
|
|
),
|
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="pressure_sealevel",
|
|
|
|
name="Pressure at Sea Level",
|
|
|
|
native_unit_of_measurement=PRESSURE_HPA,
|
|
|
|
col_heading="LDred hPa",
|
|
|
|
dtype=float,
|
|
|
|
),
|
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="humidity",
|
|
|
|
name="Humidity",
|
|
|
|
native_unit_of_measurement=PERCENTAGE,
|
|
|
|
col_heading="RF %",
|
|
|
|
dtype=int,
|
|
|
|
),
|
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="wind_speed",
|
|
|
|
name="Wind Speed",
|
|
|
|
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
|
|
|
|
col_heading=f"WG {SPEED_KILOMETERS_PER_HOUR}",
|
|
|
|
dtype=float,
|
|
|
|
),
|
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="wind_bearing",
|
|
|
|
name="Wind Bearing",
|
|
|
|
native_unit_of_measurement=DEGREE,
|
|
|
|
col_heading=f"WR {DEGREE}",
|
|
|
|
dtype=int,
|
|
|
|
),
|
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="wind_max_speed",
|
|
|
|
name="Top Wind Speed",
|
|
|
|
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
|
|
|
|
col_heading=f"WSG {SPEED_KILOMETERS_PER_HOUR}",
|
|
|
|
dtype=float,
|
2021-07-12 16:53:52 +00:00
|
|
|
),
|
2021-08-23 20:44:03 +00:00
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="wind_max_bearing",
|
|
|
|
name="Top Wind Bearing",
|
|
|
|
native_unit_of_measurement=DEGREE,
|
|
|
|
col_heading=f"WSR {DEGREE}",
|
|
|
|
dtype=int,
|
2020-02-25 01:52:14 +00:00
|
|
|
),
|
2021-08-23 20:44:03 +00:00
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="sun_last_hour",
|
|
|
|
name="Sun Last Hour",
|
|
|
|
native_unit_of_measurement=PERCENTAGE,
|
|
|
|
col_heading=f"SO {PERCENTAGE}",
|
|
|
|
dtype=int,
|
2020-02-23 20:09:24 +00:00
|
|
|
),
|
2021-08-23 20:44:03 +00:00
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="temperature",
|
|
|
|
name="Temperature",
|
|
|
|
native_unit_of_measurement=TEMP_CELSIUS,
|
2021-12-16 00:17:20 +00:00
|
|
|
device_class=SensorDeviceClass.TEMPERATURE,
|
2021-08-23 20:44:03 +00:00
|
|
|
col_heading=f"T {TEMP_CELSIUS}",
|
|
|
|
dtype=float,
|
2021-07-12 16:53:52 +00:00
|
|
|
),
|
2021-08-23 20:44:03 +00:00
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="precipitation",
|
|
|
|
name="Precipitation",
|
|
|
|
native_unit_of_measurement=f"l/{AREA_SQUARE_METERS}",
|
|
|
|
col_heading=f"N l/{AREA_SQUARE_METERS}",
|
|
|
|
dtype=float,
|
2020-09-15 21:00:26 +00:00
|
|
|
),
|
2021-08-23 20:44:03 +00:00
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="dewpoint",
|
|
|
|
name="Dew Point",
|
|
|
|
native_unit_of_measurement=TEMP_CELSIUS,
|
2021-12-16 00:17:20 +00:00
|
|
|
device_class=SensorDeviceClass.TEMPERATURE,
|
2021-08-23 20:44:03 +00:00
|
|
|
col_heading=f"TP {TEMP_CELSIUS}",
|
|
|
|
dtype=float,
|
2021-07-12 16:53:52 +00:00
|
|
|
),
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
# The following probably not useful for general consumption,
|
|
|
|
# but we need them to fill in internal attributes
|
2021-08-23 20:44:03 +00:00
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="station_name",
|
|
|
|
name="Station Name",
|
|
|
|
col_heading="Name",
|
|
|
|
dtype=str,
|
2020-04-12 19:44:56 +00:00
|
|
|
),
|
2021-08-23 20:44:03 +00:00
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="station_elevation",
|
|
|
|
name="Station Elevation",
|
|
|
|
native_unit_of_measurement=LENGTH_METERS,
|
|
|
|
col_heading=f"Höhe {LENGTH_METERS}",
|
|
|
|
dtype=int,
|
|
|
|
),
|
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="update_date",
|
|
|
|
name="Update Date",
|
|
|
|
col_heading="Datum",
|
|
|
|
dtype=str,
|
|
|
|
),
|
|
|
|
ZamgSensorEntityDescription(
|
|
|
|
key="update_time",
|
|
|
|
name="Update Time",
|
|
|
|
col_heading="Zeit",
|
|
|
|
dtype=str,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
SENSOR_KEYS: list[str] = [desc.key for desc in SENSOR_TYPES]
|
|
|
|
|
|
|
|
API_FIELDS: dict[str, tuple[str, DTypeT]] = {
|
|
|
|
desc.col_heading: (desc.key, desc.dtype) for desc in SENSOR_TYPES
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_MONITORED_CONDITIONS, default=["temperature"]): vol.All(
|
2021-08-23 20:44:03 +00:00
|
|
|
cv.ensure_list, [vol.In(SENSOR_KEYS)]
|
2019-07-31 19:25:30 +00:00
|
|
|
),
|
|
|
|
vol.Optional(CONF_STATION_ID): cv.string,
|
|
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
|
|
vol.Inclusive(
|
|
|
|
CONF_LATITUDE, "coordinates", "Latitude and longitude must exist together"
|
|
|
|
): cv.latitude,
|
|
|
|
vol.Inclusive(
|
|
|
|
CONF_LONGITUDE, "coordinates", "Latitude and longitude must exist together"
|
|
|
|
): cv.longitude,
|
|
|
|
}
|
|
|
|
)
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
|
|
|
|
2022-01-04 09:52:30 +00:00
|
|
|
def setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
add_entities: AddEntitiesCallback,
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> None:
|
2016-12-06 14:49:59 +00:00
|
|
|
"""Set up the ZAMG sensor platform."""
|
2021-08-23 20:44:03 +00:00
|
|
|
name = config[CONF_NAME]
|
2017-08-06 13:20:51 +00:00
|
|
|
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
|
|
|
|
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
2017-02-24 21:45:46 +00:00
|
|
|
station_id = config.get(CONF_STATION_ID) or closest_station(
|
2019-07-31 19:25:30 +00:00
|
|
|
latitude, longitude, hass.config.config_dir
|
|
|
|
)
|
2021-05-20 07:25:31 +00:00
|
|
|
if station_id not in _get_ogd_stations():
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.error(
|
|
|
|
"Configured ZAMG %s (%s) is not a known station",
|
|
|
|
CONF_STATION_ID,
|
|
|
|
station_id,
|
|
|
|
)
|
2022-01-04 09:52:30 +00:00
|
|
|
return
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
2017-08-06 13:20:51 +00:00
|
|
|
probe = ZamgData(station_id=station_id)
|
2017-02-24 21:45:46 +00:00
|
|
|
try:
|
|
|
|
probe.update()
|
2017-08-06 13:20:51 +00:00
|
|
|
except (ValueError, TypeError) as err:
|
|
|
|
_LOGGER.error("Received error from ZAMG: %s", err)
|
2022-01-04 09:52:30 +00:00
|
|
|
return
|
2017-02-24 21:45:46 +00:00
|
|
|
|
2021-08-23 20:44:03 +00:00
|
|
|
monitored_conditions = config[CONF_MONITORED_CONDITIONS]
|
2019-07-31 19:25:30 +00:00
|
|
|
add_entities(
|
|
|
|
[
|
2021-08-23 20:44:03 +00:00
|
|
|
ZamgSensor(probe, name, description)
|
|
|
|
for description in SENSOR_TYPES
|
|
|
|
if description.key in monitored_conditions
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
|
|
|
True,
|
|
|
|
)
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
|
|
|
|
2021-03-22 18:50:29 +00:00
|
|
|
class ZamgSensor(SensorEntity):
|
2016-12-06 14:49:59 +00:00
|
|
|
"""Implementation of a ZAMG sensor."""
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
2021-08-23 20:44:03 +00:00
|
|
|
entity_description: ZamgSensorEntityDescription
|
|
|
|
|
|
|
|
def __init__(self, probe, name, description: ZamgSensorEntityDescription):
|
2016-12-06 14:49:59 +00:00
|
|
|
"""Initialize the sensor."""
|
2021-08-23 20:44:03 +00:00
|
|
|
self.entity_description = description
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
self.probe = probe
|
2021-08-23 20:44:03 +00:00
|
|
|
self._attr_name = f"{name} {description.key}"
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
|
|
|
@property
|
2021-08-11 19:17:16 +00:00
|
|
|
def native_value(self):
|
2016-12-06 14:49:59 +00:00
|
|
|
"""Return the state of the sensor."""
|
2021-08-23 20:44:03 +00:00
|
|
|
return self.probe.get_data(self.entity_description.key)
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
|
|
|
@property
|
2021-03-11 19:16:26 +00:00
|
|
|
def extra_state_attributes(self):
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
"""Return the state attributes."""
|
|
|
|
return {
|
2019-12-19 13:00:22 +00:00
|
|
|
ATTR_ATTRIBUTION: ATTRIBUTION,
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_STATION: self.probe.get_data("station_name"),
|
2017-02-24 21:45:46 +00:00
|
|
|
ATTR_UPDATED: self.probe.last_update.isoformat(),
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 13:20:51 +00:00
|
|
|
def update(self):
|
|
|
|
"""Delegate update to probe."""
|
|
|
|
self.probe.update()
|
|
|
|
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
2018-07-20 08:45:20 +00:00
|
|
|
class ZamgData:
|
2016-12-06 14:49:59 +00:00
|
|
|
"""The class for handling the data retrieval."""
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
API_URL = "http://www.zamg.ac.at/ogd/"
|
2020-04-05 15:48:55 +00:00
|
|
|
API_HEADERS = {USER_AGENT: f"home-assistant.zamg/ {__version__}"}
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
2017-08-06 13:20:51 +00:00
|
|
|
def __init__(self, station_id):
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
"""Initialize the probe."""
|
|
|
|
self._station_id = station_id
|
|
|
|
self.data = {}
|
|
|
|
|
2017-02-24 21:45:46 +00:00
|
|
|
@property
|
|
|
|
def last_update(self):
|
|
|
|
"""Return the timestamp of the most recent data."""
|
2019-07-31 19:25:30 +00:00
|
|
|
date, time = self.data.get("update_date"), self.data.get("update_time")
|
2017-02-24 21:45:46 +00:00
|
|
|
if date is not None and time is not None:
|
2019-07-31 19:25:30 +00:00
|
|
|
return datetime.strptime(date + time, "%d-%m-%Y%H:%M").replace(
|
2021-05-08 05:46:26 +00:00
|
|
|
tzinfo=VIENNA_TIME_ZONE
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2017-02-24 21:45:46 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def current_observations(cls):
|
|
|
|
"""Fetch the latest CSV data."""
|
|
|
|
try:
|
2019-07-31 19:25:30 +00:00
|
|
|
response = requests.get(cls.API_URL, headers=cls.API_HEADERS, timeout=15)
|
2017-02-24 21:45:46 +00:00
|
|
|
response.raise_for_status()
|
2019-07-31 19:25:30 +00:00
|
|
|
response.encoding = "UTF8"
|
2017-11-04 19:04:05 +00:00
|
|
|
return csv.DictReader(
|
2019-07-31 19:25:30 +00:00
|
|
|
response.text.splitlines(), delimiter=";", quotechar='"'
|
|
|
|
)
|
2017-08-06 13:20:51 +00:00
|
|
|
except requests.exceptions.HTTPError:
|
|
|
|
_LOGGER.error("While fetching data")
|
2017-02-24 21:45:46 +00:00
|
|
|
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
|
|
|
def update(self):
|
2016-12-06 14:49:59 +00:00
|
|
|
"""Get the latest data from ZAMG."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.last_update and (
|
|
|
|
self.last_update + timedelta(hours=1)
|
2021-05-08 05:46:26 +00:00
|
|
|
> datetime.utcnow().replace(tzinfo=dt_util.UTC)
|
2019-07-31 19:25:30 +00:00
|
|
|
):
|
2017-02-24 21:45:46 +00:00
|
|
|
return # Not time to update yet; data is only hourly
|
|
|
|
|
|
|
|
for row in self.current_observations():
|
2019-07-31 19:25:30 +00:00
|
|
|
if row.get("Station") == self._station_id:
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
self.data = {
|
2021-08-23 20:44:03 +00:00
|
|
|
API_FIELDS[col_heading][0]: API_FIELDS[col_heading][1](
|
2019-07-31 19:25:30 +00:00
|
|
|
v.replace(",", ".")
|
|
|
|
)
|
2017-02-24 21:45:46 +00:00
|
|
|
for col_heading, v in row.items()
|
2021-08-23 20:44:03 +00:00
|
|
|
if col_heading in API_FIELDS and v
|
2019-07-31 19:25:30 +00:00
|
|
|
}
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
break
|
2017-02-24 21:45:46 +00:00
|
|
|
else:
|
2019-09-03 19:15:31 +00:00
|
|
|
raise ValueError(f"No weather data for station {self._station_id}")
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
|
|
|
|
def get_data(self, variable):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Get the data."""
|
Add sensor for reading Austrian ZAMG weather conditions (#4347)
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Add sensor for reading ZAMG weather conditions
* Add to coveragerc; Correct some doc style problems
* More doc fixes
* More doc fixes
* Verify that the configured station id is actually one in the data set.
Don't warn about unknown stations, this cannot happen any more as the configuration parser now checks that.
This could still happen if the data set is incomplete though ...
* Lose license and whatever.
* Don't return UNKNOWN for unknown variables
* Clean up imports
* Clarify comment on throttling interval
* Base zamg sensor on Entity, not WeatherEntity, and delete unused code
* Fix formatting nits from flake8
* Use ATTR_FRIENDLY_NAME, clean up imports, remove unnecessary indirection.
* Use {}.format() instead of "" %
* Re-add unit of measurement that got lost somehow
* Use guard clauses instead of if-matroshka.
Wrap requests.get() in try/except for RequestException.
* Huh, how did this happen? White space corrections...
* Precipitation actually is a float, good it rained today
* Logger needs no module visibility
* Do not name sensors with _ to be in line with the other weather sensor platforms.
* Remove manually set friendly_name
* comment format police
* Less comments
* Update zamg.py
2016-12-06 01:50:50 +00:00
|
|
|
return self.data.get(variable)
|
2017-02-24 21:45:46 +00:00
|
|
|
|
|
|
|
|
2021-05-20 07:25:31 +00:00
|
|
|
def _get_ogd_stations():
|
|
|
|
"""Return all stations in the OGD dataset."""
|
|
|
|
return {r["Station"] for r in ZamgData.current_observations()}
|
|
|
|
|
|
|
|
|
2017-02-24 21:45:46 +00:00
|
|
|
def _get_zamg_stations():
|
|
|
|
"""Return {CONF_STATION: (lat, lon)} for all stations, for auto-config."""
|
2021-05-20 07:25:31 +00:00
|
|
|
capital_stations = _get_ogd_stations()
|
2019-07-31 19:25:30 +00:00
|
|
|
req = requests.get(
|
|
|
|
"https://www.zamg.ac.at/cms/en/documents/climate/"
|
|
|
|
"doc_metnetwork/zamg-observation-points",
|
|
|
|
timeout=15,
|
|
|
|
)
|
2017-02-24 21:45:46 +00:00
|
|
|
stations = {}
|
2019-07-31 19:25:30 +00:00
|
|
|
for row in csv.DictReader(req.text.splitlines(), delimiter=";", quotechar='"'):
|
|
|
|
if row.get("synnr") in capital_stations:
|
2017-02-24 21:45:46 +00:00
|
|
|
try:
|
2019-07-31 19:25:30 +00:00
|
|
|
stations[row["synnr"]] = tuple(
|
|
|
|
float(row[coord].replace(",", "."))
|
2021-07-19 13:57:06 +00:00
|
|
|
for coord in ("breite_dezi", "länge_dezi")
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2017-02-24 21:45:46 +00:00
|
|
|
except KeyError:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.error("ZAMG schema changed again, cannot autodetect station")
|
2017-02-24 21:45:46 +00:00
|
|
|
return stations
|
|
|
|
|
|
|
|
|
|
|
|
def zamg_stations(cache_dir):
|
|
|
|
"""Return {CONF_STATION: (lat, lon)} for all stations, for auto-config.
|
|
|
|
|
|
|
|
Results from internet requests are cached as compressed json, making
|
|
|
|
subsequent calls very much faster.
|
|
|
|
"""
|
2019-07-31 19:25:30 +00:00
|
|
|
cache_file = os.path.join(cache_dir, ".zamg-stations.json.gz")
|
2017-02-24 21:45:46 +00:00
|
|
|
if not os.path.isfile(cache_file):
|
|
|
|
stations = _get_zamg_stations()
|
2019-07-31 19:25:30 +00:00
|
|
|
with gzip.open(cache_file, "wt") as cache:
|
2017-02-24 21:45:46 +00:00
|
|
|
json.dump(stations, cache, sort_keys=True)
|
|
|
|
return stations
|
2019-07-31 19:25:30 +00:00
|
|
|
with gzip.open(cache_file, "rt") as cache:
|
2017-02-24 21:45:46 +00:00
|
|
|
return {k: tuple(v) for k, v in json.load(cache).items()}
|
|
|
|
|
|
|
|
|
|
|
|
def closest_station(lat, lon, cache_dir):
|
|
|
|
"""Return the ZONE_ID.WMO_ID of the closest station to our lat/lon."""
|
|
|
|
if lat is None or lon is None or not os.path.isdir(cache_dir):
|
|
|
|
return
|
|
|
|
stations = zamg_stations(cache_dir)
|
|
|
|
|
|
|
|
def comparable_dist(zamg_id):
|
2018-01-29 22:37:19 +00:00
|
|
|
"""Calculate the pseudo-distance from lat/lon."""
|
2017-02-24 21:45:46 +00:00
|
|
|
station_lat, station_lon = stations[zamg_id]
|
|
|
|
return (lat - station_lat) ** 2 + (lon - station_lon) ** 2
|
|
|
|
|
|
|
|
return min(stations, key=comparable_dist)
|