diff --git a/homeassistant/components/accuweather/sensor.py b/homeassistant/components/accuweather/sensor.py index ba99df14d9e..3a774afe341 100644 --- a/homeassistant/components/accuweather/sensor.py +++ b/homeassistant/components/accuweather/sensor.py @@ -13,7 +13,6 @@ from homeassistant.const import ( DEVICE_CLASS_TEMPERATURE, ) from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -84,32 +83,27 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity): else: self._description = FORECAST_SENSOR_TYPES[kind] self._unit_system = API_METRIC if coordinator.is_metric else API_IMPERIAL - self._name = name self.kind = kind - self._device_class = None self._attrs = {ATTR_ATTRIBUTION: ATTRIBUTION} self.forecast_day = forecast_day self._attr_state_class = self._description.get(ATTR_STATE_CLASS) - - @property - def name(self) -> str: - """Return the name.""" + self._attr_icon = self._description[ATTR_ICON] + self._attr_device_class = self._description[ATTR_DEVICE_CLASS] + self._attr_entity_registry_enabled_default = self._description[ATTR_ENABLED] if self.forecast_day is not None: - return f"{self._name} {self._description[ATTR_LABEL]} {self.forecast_day}d" - return f"{self._name} {self._description[ATTR_LABEL]}" - - @property - def unique_id(self) -> str: - """Return a unique_id for this entity.""" - if self.forecast_day is not None: - return f"{self.coordinator.location_key}-{self.kind}-{self.forecast_day}".lower() - return f"{self.coordinator.location_key}-{self.kind}".lower() - - @property - def device_info(self) -> DeviceInfo: - """Return the device info.""" - return { - "identifiers": {(DOMAIN, self.coordinator.location_key)}, + self._attr_name = f"{name} {self._description[ATTR_LABEL]} {forecast_day}d" + self._attr_unique_id = ( + f"{coordinator.location_key}-{kind}-{forecast_day}".lower() + ) + else: + self._attr_name = f"{name} {self._description[ATTR_LABEL]}" + self._attr_unique_id = f"{coordinator.location_key}-{kind}".lower() + if coordinator.is_metric: + self._attr_unit_of_measurement = self._description[ATTR_UNIT_METRIC] + else: + self._attr_unit_of_measurement = self._description[ATTR_UNIT_IMPERIAL] + self._attr_device_info = { + "identifiers": {(DOMAIN, coordinator.location_key)}, "name": NAME, "manufacturer": MANUFACTURER, "entry_type": "service", @@ -139,23 +133,6 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity): return cast(StateType, self._sensor_data["Speed"]["Value"]) return cast(StateType, self._sensor_data) - @property - def icon(self) -> str | None: - """Return the icon.""" - return self._description[ATTR_ICON] - - @property - def device_class(self) -> str | None: - """Return the device_class.""" - return self._description[ATTR_DEVICE_CLASS] - - @property - def unit_of_measurement(self) -> str | None: - """Return the unit the value is expressed in.""" - if self.coordinator.is_metric: - return self._description[ATTR_UNIT_METRIC] - return self._description[ATTR_UNIT_IMPERIAL] - @property def extra_state_attributes(self) -> dict[str, Any]: """Return the state attributes.""" @@ -171,11 +148,6 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity): self._attrs["type"] = self.coordinator.data["PrecipitationType"] return self._attrs - @property - def entity_registry_enabled_default(self) -> bool: - """Return if the entity should be enabled when first added to the entity registry.""" - return self._description[ATTR_ENABLED] - @callback def _handle_coordinator_update(self) -> None: """Handle data update.""" diff --git a/homeassistant/components/accuweather/weather.py b/homeassistant/components/accuweather/weather.py index 9a2ba769a82..cd8d64cc80f 100644 --- a/homeassistant/components/accuweather/weather.py +++ b/homeassistant/components/accuweather/weather.py @@ -19,7 +19,6 @@ from homeassistant.components.weather import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME, TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.util.dt import utc_from_timestamp @@ -60,29 +59,15 @@ class AccuWeatherEntity(CoordinatorEntity, WeatherEntity): ) -> None: """Initialize.""" super().__init__(coordinator) - self._name = name - self._unit_system = API_METRIC if self.coordinator.is_metric else API_IMPERIAL - - @property - def name(self) -> str: - """Return the name.""" - return self._name - - @property - def attribution(self) -> str: - """Return the attribution.""" - return ATTRIBUTION - - @property - def unique_id(self) -> str: - """Return a unique_id for this entity.""" - return self.coordinator.location_key - - @property - def device_info(self) -> DeviceInfo: - """Return the device info.""" - return { - "identifiers": {(DOMAIN, self.coordinator.location_key)}, + self._unit_system = API_METRIC if coordinator.is_metric else API_IMPERIAL + self._attr_name = name + self._attr_unique_id = coordinator.location_key + self._attr_temperature_unit = ( + TEMP_CELSIUS if coordinator.is_metric else TEMP_FAHRENHEIT + ) + self._attr_attribution = ATTRIBUTION + self._attr_device_info = { + "identifiers": {(DOMAIN, coordinator.location_key)}, "name": NAME, "manufacturer": MANUFACTURER, "entry_type": "service", @@ -107,11 +92,6 @@ class AccuWeatherEntity(CoordinatorEntity, WeatherEntity): float, self.coordinator.data["Temperature"][self._unit_system]["Value"] ) - @property - def temperature_unit(self) -> str: - """Return the unit of measurement.""" - return TEMP_CELSIUS if self.coordinator.is_metric else TEMP_FAHRENHEIT - @property def pressure(self) -> float: """Return the pressure."""