diff --git a/homeassistant/components/garages_amsterdam/binary_sensor.py b/homeassistant/components/garages_amsterdam/binary_sensor.py index cb2ba8906bc..5b444146624 100644 --- a/homeassistant/components/garages_amsterdam/binary_sensor.py +++ b/homeassistant/components/garages_amsterdam/binary_sensor.py @@ -1,14 +1,11 @@ """Binary Sensor platform for Garages Amsterdam.""" from __future__ import annotations -from typing import Any - from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_PROBLEM, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import ( @@ -43,25 +40,18 @@ async def async_setup_entry( class GaragesamsterdamBinarySensor(CoordinatorEntity, BinarySensorEntity): """Binary Sensor representing garages amsterdam data.""" + _attr_attribution = ATTRIBUTION + _attr_device_class = BinarySensorDeviceClass.PROBLEM + def __init__( self, coordinator: DataUpdateCoordinator, garage_name: str, info_type: str ) -> None: """Initialize garages amsterdam binary sensor.""" super().__init__(coordinator) - self._unique_id = f"{garage_name}-{info_type}" + self._attr_unique_id = f"{garage_name}-{info_type}" self._garage_name = garage_name self._info_type = info_type - self._name = garage_name - - @property - def name(self) -> str: - """Return the name of the sensor.""" - return self._name - - @property - def unique_id(self) -> str: - """Return the unique id of the device.""" - return self._unique_id + self._attr_name = garage_name @property def is_on(self) -> bool: @@ -69,13 +59,3 @@ class GaragesamsterdamBinarySensor(CoordinatorEntity, BinarySensorEntity): return ( getattr(self.coordinator.data[self._garage_name], self._info_type) != "ok" ) - - @property - def device_class(self) -> str: - """Return the class of the binary sensor.""" - return DEVICE_CLASS_PROBLEM - - @property - def extra_state_attributes(self) -> dict[str, Any]: - """Return device attributes.""" - return {ATTR_ATTRIBUTION: ATTRIBUTION} diff --git a/homeassistant/components/garages_amsterdam/sensor.py b/homeassistant/components/garages_amsterdam/sensor.py index da3a7a4dc24..252f010dfdb 100644 --- a/homeassistant/components/garages_amsterdam/sensor.py +++ b/homeassistant/components/garages_amsterdam/sensor.py @@ -1,11 +1,8 @@ """Sensor platform for Garages Amsterdam.""" from __future__ import annotations -from typing import Any - from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import ( @@ -48,25 +45,19 @@ async def async_setup_entry( class GaragesamsterdamSensor(CoordinatorEntity, SensorEntity): """Sensor representing garages amsterdam data.""" + _attr_attribution = ATTRIBUTION + _attr_native_unit_of_measurement = "cars" + def __init__( self, coordinator: DataUpdateCoordinator, garage_name: str, info_type: str ) -> None: """Initialize garages amsterdam sensor.""" super().__init__(coordinator) - self._unique_id = f"{garage_name}-{info_type}" + self._attr_unique_id = f"{garage_name}-{info_type}" self._garage_name = garage_name self._info_type = info_type - self._name = f"{garage_name} - {info_type}".replace("_", " ") - - @property - def name(self) -> str: - """Return the name of the sensor.""" - return self._name - - @property - def unique_id(self) -> str: - """Return the unique id of the device.""" - return self._unique_id + self._attr_name = f"{garage_name} - {info_type}".replace("_", " ") + self._attr_icon = SENSORS[info_type] @property def available(self) -> bool: @@ -79,18 +70,3 @@ class GaragesamsterdamSensor(CoordinatorEntity, SensorEntity): def native_value(self) -> str: """Return the state of the sensor.""" return getattr(self.coordinator.data[self._garage_name], self._info_type) - - @property - def icon(self) -> str: - """Return the icon.""" - return SENSORS[self._info_type] - - @property - def native_unit_of_measurement(self) -> str: - """Return unit of measurement.""" - return "cars" - - @property - def extra_state_attributes(self) -> dict[str, Any]: - """Return device attributes.""" - return {ATTR_ATTRIBUTION: ATTRIBUTION}