1
mirror of https://github.com/home-assistant/core synced 2024-10-04 07:58:43 +02:00

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>
This commit is contained in:
andarotajo 2023-04-05 09:16:17 +02:00 committed by GitHub
parent 5eb0c35a97
commit 08dd0a5efa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 33 deletions

View File

@ -226,6 +226,7 @@ omit =
homeassistant/components/dublin_bus_transport/sensor.py homeassistant/components/dublin_bus_transport/sensor.py
homeassistant/components/dunehd/__init__.py homeassistant/components/dunehd/__init__.py
homeassistant/components/dunehd/media_player.py homeassistant/components/dunehd/media_player.py
homeassistant/components/dwd_weather_warnings/const.py
homeassistant/components/dwd_weather_warnings/sensor.py homeassistant/components/dwd_weather_warnings/sensor.py
homeassistant/components/dweet/* homeassistant/components/dweet/*
homeassistant/components/ebox/sensor.py homeassistant/components/ebox/sensor.py

View File

@ -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)

View File

@ -10,9 +10,6 @@ Wetterwarnungen (Stufe 1)
""" """
from __future__ import annotations from __future__ import annotations
from datetime import timedelta
import logging
from dwdwfsapi import DwdWeatherWarningsAPI from dwdwfsapi import DwdWeatherWarningsAPI
import voluptuous as vol import voluptuous as vol
@ -28,33 +25,28 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import Throttle from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__) from .const import (
ADVANCE_WARNING_SENSOR,
ATTR_REGION_NAME = "region_name" API_ATTR_WARNING_COLOR,
ATTR_REGION_ID = "region_id" API_ATTR_WARNING_DESCRIPTION,
ATTR_LAST_UPDATE = "last_update" API_ATTR_WARNING_END,
ATTR_WARNING_COUNT = "warning_count" API_ATTR_WARNING_HEADLINE,
API_ATTR_WARNING_INSTRUCTION,
API_ATTR_WARNING_NAME = "event" API_ATTR_WARNING_LEVEL,
API_ATTR_WARNING_TYPE = "event_code" API_ATTR_WARNING_NAME,
API_ATTR_WARNING_LEVEL = "level" API_ATTR_WARNING_PARAMETERS,
API_ATTR_WARNING_HEADLINE = "headline" API_ATTR_WARNING_START,
API_ATTR_WARNING_DESCRIPTION = "description" API_ATTR_WARNING_TYPE,
API_ATTR_WARNING_INSTRUCTION = "instruction" ATTR_LAST_UPDATE,
API_ATTR_WARNING_START = "start_time" ATTR_REGION_ID,
API_ATTR_WARNING_END = "end_time" ATTR_REGION_NAME,
API_ATTR_WARNING_PARAMETERS = "parameters" ATTR_WARNING_COUNT,
API_ATTR_WARNING_COLOR = "color" CONF_REGION_NAME,
CURRENT_WARNING_SENSOR,
DEFAULT_NAME = "DWD-Weather-Warnings" DEFAULT_NAME,
DEFAULT_SCAN_INTERVAL,
CONF_REGION_NAME = "region_name" LOGGER,
)
CURRENT_WARNING_SENSOR = "current_warning_level"
ADVANCE_WARNING_SENSOR = "advance_warning_level"
SCAN_INTERVAL = timedelta(minutes=15)
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
@ -169,7 +161,7 @@ class DwdWeatherWarningsSensor(SensorEntity):
def update(self) -> None: def update(self) -> None:
"""Get the latest data from the DWD-Weather-Warnings API.""" """Get the latest data from the DWD-Weather-Warnings API."""
_LOGGER.debug( LOGGER.debug(
"Update requested for %s (%s) by %s", "Update requested for %s (%s) by %s",
self._api.api.warncell_name, self._api.api.warncell_name,
self._api.api.warncell_id, self._api.api.warncell_id,
@ -185,8 +177,8 @@ class WrappedDwDWWAPI:
"""Initialize a DWD-Weather-Warnings wrapper.""" """Initialize a DWD-Weather-Warnings wrapper."""
self.api = api self.api = api
@Throttle(SCAN_INTERVAL) @Throttle(DEFAULT_SCAN_INTERVAL)
def update(self): def update(self):
"""Get the latest data from the DWD-Weather-Warnings API.""" """Get the latest data from the DWD-Weather-Warnings API."""
self.api.update() self.api.update()
_LOGGER.debug("Update performed") LOGGER.debug("Update performed")