Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
FL550 committed Feb 6, 2024
1 parent 19bfc35 commit 3e795f6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
39 changes: 23 additions & 16 deletions custom_components/dwd_weather/connector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Connector class to retrieve data, which is use by the weather and sensor enities."""

import logging
from datetime import datetime, timedelta, timezone
import time
Expand Down Expand Up @@ -92,10 +93,12 @@ def _update(self):
self.dwd_weather.update(
force_hourly=self._config[CONF_HOURLY_UPDATE],
with_forecast=True,
with_measurements=True
if self._config[CONF_DATA_TYPE] == CONF_DATA_TYPE_REPORT
or self._config[CONF_DATA_TYPE] == CONF_DATA_TYPE_MIXED
else False,
with_measurements=(
True
if self._config[CONF_DATA_TYPE] == CONF_DATA_TYPE_REPORT
or self._config[CONF_DATA_TYPE] == CONF_DATA_TYPE_MIXED
else False
),
with_report=True,
)
if self._config[CONF_HOURLY_UPDATE]:
Expand Down Expand Up @@ -240,12 +243,12 @@ def get_forecast(self, WeatherEntityFeature_FORECAST) -> list[Forecast] | None:
False,
),
ATTR_FORECAST_WIND_BEARING: wind_dir,
ATTR_FORECAST_NATIVE_WIND_SPEED: round(wind_speed * 3.6, 1)
if wind_speed is not None
else None,
ATTR_WEATHER_WIND_GUST_SPEED: round(wind_gusts * 3.6, 1)
if wind_gusts is not None
else None,
ATTR_FORECAST_NATIVE_WIND_SPEED: (
round(wind_speed * 3.6, 1) if wind_speed is not None else None
),
ATTR_WEATHER_WIND_GUST_SPEED: (
round(wind_gusts * 3.6, 1) if wind_gusts is not None else None
),
"uv_index": uv_index,
"precipitation_probability": precipitation_prop,
}
Expand Down Expand Up @@ -314,9 +317,11 @@ def get_weather_value(self, data_type: WeatherDataType):
WeatherDataType.DEWPOINT: lambda x: round(x - 273.1, 1),
WeatherDataType.PRESSURE: lambda x: round(x / 100, 1),
WeatherDataType.WIND_SPEED: lambda x: round(x * 3.6, 1),
WeatherDataType.WIND_DIRECTION: lambda x: round(x, 0)
if self._config[CONF_WIND_DIRECTION_TYPE] == DEFAULT_WIND_DIRECTION_TYPE
else self.get_wind_direction_symbol(round(x, 0)),
WeatherDataType.WIND_DIRECTION: lambda x: (
round(x, 0)
if self._config[CONF_WIND_DIRECTION_TYPE] == DEFAULT_WIND_DIRECTION_TYPE
else self.get_wind_direction_symbol(round(x, 0))
),
WeatherDataType.WIND_GUSTS: lambda x: round(x * 3.6, 1),
WeatherDataType.PRECIPITATION: lambda x: round(x, 1),
WeatherDataType.PRECIPITATION_PROBABILITY: lambda x: round(x, 0),
Expand Down Expand Up @@ -412,9 +417,11 @@ def get_hourly(self, data_type: WeatherDataType):
WeatherDataType.DEWPOINT: lambda value: round(value - 273.1, 1),
WeatherDataType.PRESSURE: lambda value: round(value / 100, 1),
WeatherDataType.WIND_SPEED: lambda value: round(value * 3.6, 1),
WeatherDataType.WIND_DIRECTION: lambda value: round(value, 0)
if self._config[CONF_WIND_DIRECTION_TYPE] == DEFAULT_WIND_DIRECTION_TYPE
else self.get_wind_direction_symbol(round(value, 0)),
WeatherDataType.WIND_DIRECTION: lambda value: (
round(value, 0)
if self._config[CONF_WIND_DIRECTION_TYPE] == DEFAULT_WIND_DIRECTION_TYPE
else self.get_wind_direction_symbol(round(value, 0))
),
WeatherDataType.WIND_GUSTS: lambda value: round(value * 3.6, 1),
WeatherDataType.PRECIPITATION: lambda value: round(value, 1),
WeatherDataType.PRECIPITATION_PROBABILITY: lambda value: round(value, 0),
Expand Down
1 change: 1 addition & 0 deletions custom_components/dwd_weather/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants for the DWD Weather integration."""

from datetime import timedelta

from homeassistant.const import Platform
Expand Down
5 changes: 4 additions & 1 deletion custom_components/dwd_weather/entity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""DWDWeatherEntity class."""

import logging
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
Expand All @@ -23,7 +24,9 @@ def __init__(self, hass_data, unique_id):
self._connector = hass_data[DWDWEATHER_DATA]
self._coordinator = hass_data[DWDWEATHER_COORDINATOR]
self._station_name = self._connector._config[CONF_STATION_NAME]
self._device_id = f"{self._connector.dwd_weather.station_id}: {self._station_name}"
self._device_id = (
f"{self._connector.dwd_weather.station_id}: {self._station_name}"
)
self._unique_id = unique_id

@property
Expand Down
1 change: 1 addition & 0 deletions custom_components/dwd_weather/weather.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for DWD weather service."""

import logging
from custom_components.dwd_weather.connector import DWDWeatherData
from custom_components.dwd_weather.entity import DWDWeatherEntity
Expand Down

0 comments on commit 3e795f6

Please sign in to comment.