Skip to content

Commit

Permalink
Clean out compatibility for deprecated methods in Weather (#99263)
Browse files Browse the repository at this point in the history
Clean out compatability in Weather
  • Loading branch information
gjohansson-ST committed Aug 29, 2023
1 parent e6eadc7 commit 657ed0b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 490 deletions.
186 changes: 0 additions & 186 deletions homeassistant/components/weather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,35 +274,8 @@ class WeatherEntity(Entity, PostInit):
_attr_cloud_coverage: int | None = None
_attr_uv_index: float | None = None
_attr_precision: float
_attr_pressure: None = (
None # Provide backwards compatibility. Use _attr_native_pressure
)
_attr_pressure_unit: None = (
None # Provide backwards compatibility. Use _attr_native_pressure_unit
)
_attr_state: None = None
_attr_temperature: None = (
None # Provide backwards compatibility. Use _attr_native_temperature
)
_attr_temperature_unit: None = (
None # Provide backwards compatibility. Use _attr_native_temperature_unit
)
_attr_visibility: None = (
None # Provide backwards compatibility. Use _attr_native_visibility
)
_attr_visibility_unit: None = (
None # Provide backwards compatibility. Use _attr_native_visibility_unit
)
_attr_precipitation_unit: None = (
None # Provide backwards compatibility. Use _attr_native_precipitation_unit
)
_attr_wind_bearing: float | str | None = None
_attr_wind_speed: None = (
None # Provide backwards compatibility. Use _attr_native_wind_speed
)
_attr_wind_speed_unit: None = (
None # Provide backwards compatibility. Use _attr_native_wind_speed_unit
)

_attr_native_pressure: float | None = None
_attr_native_pressure_unit: str | None = None
Expand All @@ -322,8 +295,6 @@ class WeatherEntity(Entity, PostInit):
list[Callable[[list[JsonValueType] | None], None]],
]
__weather_legacy_forecast: bool = False
__weather_legacy_forecast_reported: bool = False
__report_issue: str

_weather_option_temperature_unit: str | None = None
_weather_option_pressure_unit: str | None = None
Expand All @@ -338,55 +309,6 @@ def __post_init__(self, *args: Any, **kwargs: Any) -> None:
def __init_subclass__(cls, **kwargs: Any) -> None:
"""Post initialisation processing."""
super().__init_subclass__(**kwargs)

_reported = False
if any(
method in cls.__dict__
for method in (
"_attr_temperature",
"temperature",
"_attr_temperature_unit",
"temperature_unit",
"_attr_pressure",
"pressure",
"_attr_pressure_unit",
"pressure_unit",
"_attr_wind_speed",
"wind_speed",
"_attr_wind_speed_unit",
"wind_speed_unit",
"_attr_visibility",
"visibility",
"_attr_visibility_unit",
"visibility_unit",
"_attr_precipitation_unit",
"precipitation_unit",
)
):
if _reported is False:
module = inspect.getmodule(cls)
_reported = True
if (
module
and module.__file__
and "custom_components" in module.__file__
):
report_issue = "report it to the custom integration author."
else:
report_issue = (
"create a bug report at "
"https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue"
)
_LOGGER.warning(
(
"%s::%s is overriding deprecated methods on an instance of "
"WeatherEntity, this is not valid and will be unsupported "
"from Home Assistant 2023.1. Please %s"
),
cls.__module__,
cls.__name__,
report_issue,
)
if any(
method in cls.__dict__ for method in ("_attr_forecast", "forecast")
) and not any(
Expand Down Expand Up @@ -453,45 +375,21 @@ def native_apparent_temperature(self) -> float | None:
"""Return the apparent temperature in native units."""
return self._attr_native_temperature

@final
@property
def temperature(self) -> float | None:
"""Return the temperature for backward compatibility.
Should not be set by integrations.
"""
return self._attr_temperature

@property
def native_temperature(self) -> float | None:
"""Return the temperature in native units."""
if (temperature := self.temperature) is not None:
return temperature

return self._attr_native_temperature

@property
def native_temperature_unit(self) -> str | None:
"""Return the native unit of measurement for temperature."""
if (temperature_unit := self.temperature_unit) is not None:
return temperature_unit

return self._attr_native_temperature_unit

@property
def native_dew_point(self) -> float | None:
"""Return the dew point temperature in native units."""
return self._attr_native_dew_point

@final
@property
def temperature_unit(self) -> str | None:
"""Return the temperature unit for backward compatibility.
Should not be set by integrations.
"""
return self._attr_temperature_unit

@final
@property
def _default_temperature_unit(self) -> str:
Expand All @@ -515,40 +413,16 @@ def _temperature_unit(self) -> str:

return self._default_temperature_unit

@final
@property
def pressure(self) -> float | None:
"""Return the pressure for backward compatibility.
Should not be set by integrations.
"""
return self._attr_pressure

@property
def native_pressure(self) -> float | None:
"""Return the pressure in native units."""
if (pressure := self.pressure) is not None:
return pressure

return self._attr_native_pressure

@property
def native_pressure_unit(self) -> str | None:
"""Return the native unit of measurement for pressure."""
if (pressure_unit := self.pressure_unit) is not None:
return pressure_unit

return self._attr_native_pressure_unit

@final
@property
def pressure_unit(self) -> str | None:
"""Return the pressure unit for backward compatibility.
Should not be set by integrations.
"""
return self._attr_pressure_unit

@final
@property
def _default_pressure_unit(self) -> str:
Expand Down Expand Up @@ -584,40 +458,16 @@ def native_wind_gust_speed(self) -> float | None:
"""Return the wind gust speed in native units."""
return self._attr_native_wind_gust_speed

@final
@property
def wind_speed(self) -> float | None:
"""Return the wind_speed for backward compatibility.
Should not be set by integrations.
"""
return self._attr_wind_speed

@property
def native_wind_speed(self) -> float | None:
"""Return the wind speed in native units."""
if (wind_speed := self.wind_speed) is not None:
return wind_speed

return self._attr_native_wind_speed

@property
def native_wind_speed_unit(self) -> str | None:
"""Return the native unit of measurement for wind speed."""
if (wind_speed_unit := self.wind_speed_unit) is not None:
return wind_speed_unit

return self._attr_native_wind_speed_unit

@final
@property
def wind_speed_unit(self) -> str | None:
"""Return the wind_speed unit for backward compatibility.
Should not be set by integrations.
"""
return self._attr_wind_speed_unit

@final
@property
def _default_wind_speed_unit(self) -> str:
Expand Down Expand Up @@ -663,40 +513,16 @@ def uv_index(self) -> float | None:
"""Return the UV index."""
return self._attr_uv_index

@final
@property
def visibility(self) -> float | None:
"""Return the visibility for backward compatibility.
Should not be set by integrations.
"""
return self._attr_visibility

@property
def native_visibility(self) -> float | None:
"""Return the visibility in native units."""
if (visibility := self.visibility) is not None:
return visibility

return self._attr_native_visibility

@property
def native_visibility_unit(self) -> str | None:
"""Return the native unit of measurement for visibility."""
if (visibility_unit := self.visibility_unit) is not None:
return visibility_unit

return self._attr_native_visibility_unit

@final
@property
def visibility_unit(self) -> str | None:
"""Return the visibility unit for backward compatibility.
Should not be set by integrations.
"""
return self._attr_visibility_unit

@final
@property
def _default_visibility_unit(self) -> str:
Expand Down Expand Up @@ -743,20 +569,8 @@ async def async_forecast_hourly(self) -> list[Forecast] | None:
@property
def native_precipitation_unit(self) -> str | None:
"""Return the native unit of measurement for accumulated precipitation."""
if (precipitation_unit := self.precipitation_unit) is not None:
return precipitation_unit

return self._attr_native_precipitation_unit

@final
@property
def precipitation_unit(self) -> str | None:
"""Return the precipitation unit for backward compatibility.
Should not be set by integrations.
"""
return self._attr_precipitation_unit

@final
@property
def _default_precipitation_unit(self) -> str:
Expand Down

0 comments on commit 657ed0b

Please sign in to comment.