Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 16 additions & 64 deletions homeassistant/components/climacell/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
from homeassistant.const import (
CONF_API_VERSION,
CONF_NAME,
LENGTH_FEET,
LENGTH_KILOMETERS,
LENGTH_METERS,
LENGTH_INCHES,
LENGTH_MILES,
PRESSURE_HPA,
PRESSURE_INHG,
SPEED_KILOMETERS_PER_HOUR,
SPEED_MILES_PER_HOUR,
Expand All @@ -45,8 +42,6 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sun import is_up
from homeassistant.util import dt as dt_util
from homeassistant.util.distance import convert as distance_convert
from homeassistant.util.pressure import convert as pressure_convert
from homeassistant.util.speed import convert as speed_convert

from . import ClimaCellDataUpdateCoordinator, ClimaCellEntity
Expand Down Expand Up @@ -117,6 +112,12 @@ async def async_setup_entry(
class BaseClimaCellWeatherEntity(ClimaCellEntity, WeatherEntity):
"""Base ClimaCell weather entity."""

_attr_temperature_unit = TEMP_FAHRENHEIT
_attr_pressure_unit = PRESSURE_INHG
_attr_wind_speed_unit = SPEED_MILES_PER_HOUR
_attr_visibility_unit = LENGTH_MILES
_attr_precipitation_unit = LENGTH_INCHES

def __init__(
self,
config_entry: ConfigEntry,
Expand Down Expand Up @@ -160,21 +161,6 @@ def _forecast_dict(
else:
translated_condition = self._translate_condition(condition, True)

if self.hass.config.units.is_metric:
if precipitation:
precipitation = round(
distance_convert(precipitation / 12, LENGTH_FEET, LENGTH_METERS)
* 1000,
4,
)
if wind_speed:
wind_speed = round(
speed_convert(
wind_speed, SPEED_MILES_PER_HOUR, SPEED_KILOMETERS_PER_HOUR
),
4,
)

data = {
ATTR_FORECAST_TIME: forecast_dt.isoformat(),
ATTR_FORECAST_CONDITION: translated_condition,
Expand Down Expand Up @@ -223,55 +209,23 @@ def precipitation_type(self):

@property
@abstractmethod
def _pressure(self):
"""Return the raw pressure."""

@property
def pressure(self):
"""Return the pressure."""
if self.hass.config.units.is_metric and self._pressure:
return round(
pressure_convert(self._pressure, PRESSURE_INHG, PRESSURE_HPA), 4
)
return self._pressure
"""Return the raw pressure."""

@property
@abstractmethod
def _wind_speed(self):
"""Return the raw wind speed."""

@property
def wind_speed(self):
"""Return the wind speed."""
if self.hass.config.units.is_metric and self._wind_speed:
return round(
speed_convert(
self._wind_speed, SPEED_MILES_PER_HOUR, SPEED_KILOMETERS_PER_HOUR
),
4,
)
return self._wind_speed
"""Return the raw wind speed."""

@property
@abstractmethod
def _visibility(self):
"""Return the raw visibility."""

@property
def visibility(self):
"""Return the visibility."""
if self.hass.config.units.is_metric and self._visibility:
return round(
distance_convert(self._visibility, LENGTH_MILES, LENGTH_KILOMETERS), 4
)
return self._visibility
"""Return the raw visibility."""


class ClimaCellWeatherEntity(BaseClimaCellWeatherEntity):
"""Entity that talks to ClimaCell v4 API to retrieve weather data."""

_attr_temperature_unit = TEMP_FAHRENHEIT

@staticmethod
def _translate_condition(
condition: int | str | None, sun_is_up: bool = True
Expand All @@ -293,7 +247,7 @@ def temperature(self):
return self._get_current_property(CC_ATTR_TEMPERATURE)

@property
def _pressure(self):
def pressure(self):
"""Return the raw pressure."""
return self._get_current_property(CC_ATTR_PRESSURE)

Expand Down Expand Up @@ -321,7 +275,7 @@ def precipitation_type(self):
return PrecipitationType(precipitation_type).name.lower()

@property
def _wind_speed(self):
def wind_speed(self):
"""Return the raw wind speed."""
return self._get_current_property(CC_ATTR_WIND_SPEED)

Expand All @@ -344,7 +298,7 @@ def condition(self):
)

@property
def _visibility(self):
def visibility(self):
"""Return the raw visibility."""
return self._get_current_property(CC_ATTR_VISIBILITY)

Expand Down Expand Up @@ -418,8 +372,6 @@ def forecast(self):
class ClimaCellV3WeatherEntity(BaseClimaCellWeatherEntity):
"""Entity that talks to ClimaCell v3 API to retrieve weather data."""

_attr_temperature_unit = TEMP_FAHRENHEIT

@staticmethod
def _translate_condition(
condition: int | str | None, sun_is_up: bool = True
Expand All @@ -442,7 +394,7 @@ def temperature(self):
)

@property
def _pressure(self):
def pressure(self):
"""Return the raw pressure."""
return self._get_cc_value(self.coordinator.data[CURRENT], CC_V3_ATTR_PRESSURE)

Expand Down Expand Up @@ -471,7 +423,7 @@ def precipitation_type(self):
)

@property
def _wind_speed(self):
def wind_speed(self):
"""Return the raw wind speed."""
return self._get_cc_value(self.coordinator.data[CURRENT], CC_V3_ATTR_WIND_SPEED)

Expand All @@ -496,7 +448,7 @@ def condition(self):
)

@property
def _visibility(self):
def visibility(self):
"""Return the raw visibility."""
return self._get_cc_value(self.coordinator.data[CURRENT], CC_V3_ATTR_VISIBILITY)

Expand Down
Loading