Move dwd_weather_warnings constants to separate file (#90810)
* Move constants to seperate file * Use __package__ for the logger name Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>pull/90825/head^2
parent
5eb0c35a97
commit
08dd0a5efa
|
@ -226,6 +226,7 @@ omit =
|
|||
homeassistant/components/dublin_bus_transport/sensor.py
|
||||
homeassistant/components/dunehd/__init__.py
|
||||
homeassistant/components/dunehd/media_player.py
|
||||
homeassistant/components/dwd_weather_warnings/const.py
|
||||
homeassistant/components/dwd_weather_warnings/sensor.py
|
||||
homeassistant/components/dweet/*
|
||||
homeassistant/components/ebox/sensor.py
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
"""Constants for the dwd_weather_warnings integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Final
|
||||
|
||||
LOGGER = logging.getLogger(__package__)
|
||||
|
||||
CONF_REGION_NAME: Final = "region_name"
|
||||
|
||||
ATTR_REGION_NAME: Final = "region_name"
|
||||
ATTR_REGION_ID: Final = "region_id"
|
||||
ATTR_LAST_UPDATE: Final = "last_update"
|
||||
ATTR_WARNING_COUNT: Final = "warning_count"
|
||||
|
||||
API_ATTR_WARNING_NAME: Final = "event"
|
||||
API_ATTR_WARNING_TYPE: Final = "event_code"
|
||||
API_ATTR_WARNING_LEVEL: Final = "level"
|
||||
API_ATTR_WARNING_HEADLINE: Final = "headline"
|
||||
API_ATTR_WARNING_DESCRIPTION: Final = "description"
|
||||
API_ATTR_WARNING_INSTRUCTION: Final = "instruction"
|
||||
API_ATTR_WARNING_START: Final = "start_time"
|
||||
API_ATTR_WARNING_END: Final = "end_time"
|
||||
API_ATTR_WARNING_PARAMETERS: Final = "parameters"
|
||||
API_ATTR_WARNING_COLOR: Final = "color"
|
||||
|
||||
CURRENT_WARNING_SENSOR: Final = "current_warning_level"
|
||||
ADVANCE_WARNING_SENSOR: Final = "advance_warning_level"
|
||||
|
||||
DEFAULT_NAME: Final = "DWD-Weather-Warnings"
|
||||
DEFAULT_SCAN_INTERVAL: Final = timedelta(minutes=15)
|
|
@ -10,9 +10,6 @@ Wetterwarnungen (Stufe 1)
|
|||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from dwdwfsapi import DwdWeatherWarningsAPI
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -28,33 +25,28 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_REGION_NAME = "region_name"
|
||||
ATTR_REGION_ID = "region_id"
|
||||
ATTR_LAST_UPDATE = "last_update"
|
||||
ATTR_WARNING_COUNT = "warning_count"
|
||||
|
||||
API_ATTR_WARNING_NAME = "event"
|
||||
API_ATTR_WARNING_TYPE = "event_code"
|
||||
API_ATTR_WARNING_LEVEL = "level"
|
||||
API_ATTR_WARNING_HEADLINE = "headline"
|
||||
API_ATTR_WARNING_DESCRIPTION = "description"
|
||||
API_ATTR_WARNING_INSTRUCTION = "instruction"
|
||||
API_ATTR_WARNING_START = "start_time"
|
||||
API_ATTR_WARNING_END = "end_time"
|
||||
API_ATTR_WARNING_PARAMETERS = "parameters"
|
||||
API_ATTR_WARNING_COLOR = "color"
|
||||
|
||||
DEFAULT_NAME = "DWD-Weather-Warnings"
|
||||
|
||||
CONF_REGION_NAME = "region_name"
|
||||
|
||||
CURRENT_WARNING_SENSOR = "current_warning_level"
|
||||
ADVANCE_WARNING_SENSOR = "advance_warning_level"
|
||||
|
||||
SCAN_INTERVAL = timedelta(minutes=15)
|
||||
|
||||
from .const import (
|
||||
ADVANCE_WARNING_SENSOR,
|
||||
API_ATTR_WARNING_COLOR,
|
||||
API_ATTR_WARNING_DESCRIPTION,
|
||||
API_ATTR_WARNING_END,
|
||||
API_ATTR_WARNING_HEADLINE,
|
||||
API_ATTR_WARNING_INSTRUCTION,
|
||||
API_ATTR_WARNING_LEVEL,
|
||||
API_ATTR_WARNING_NAME,
|
||||
API_ATTR_WARNING_PARAMETERS,
|
||||
API_ATTR_WARNING_START,
|
||||
API_ATTR_WARNING_TYPE,
|
||||
ATTR_LAST_UPDATE,
|
||||
ATTR_REGION_ID,
|
||||
ATTR_REGION_NAME,
|
||||
ATTR_WARNING_COUNT,
|
||||
CONF_REGION_NAME,
|
||||
CURRENT_WARNING_SENSOR,
|
||||
DEFAULT_NAME,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
LOGGER,
|
||||
)
|
||||
|
||||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
SensorEntityDescription(
|
||||
|
@ -169,7 +161,7 @@ class DwdWeatherWarningsSensor(SensorEntity):
|
|||
|
||||
def update(self) -> None:
|
||||
"""Get the latest data from the DWD-Weather-Warnings API."""
|
||||
_LOGGER.debug(
|
||||
LOGGER.debug(
|
||||
"Update requested for %s (%s) by %s",
|
||||
self._api.api.warncell_name,
|
||||
self._api.api.warncell_id,
|
||||
|
@ -185,8 +177,8 @@ class WrappedDwDWWAPI:
|
|||
"""Initialize a DWD-Weather-Warnings wrapper."""
|
||||
self.api = api
|
||||
|
||||
@Throttle(SCAN_INTERVAL)
|
||||
@Throttle(DEFAULT_SCAN_INTERVAL)
|
||||
def update(self):
|
||||
"""Get the latest data from the DWD-Weather-Warnings API."""
|
||||
self.api.update()
|
||||
_LOGGER.debug("Update performed")
|
||||
LOGGER.debug("Update performed")
|
||||
|
|
Loading…
Reference in New Issue