Use attr* in garages_amsterdam (#61605)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/61738/head
parent
905295707d
commit
85607970cf
|
@ -1,14 +1,11 @@
|
||||||
"""Binary Sensor platform for Garages Amsterdam."""
|
"""Binary Sensor platform for Garages Amsterdam."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
DEVICE_CLASS_PROBLEM,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
|
@ -43,25 +40,18 @@ async def async_setup_entry(
|
||||||
class GaragesamsterdamBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
class GaragesamsterdamBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
||||||
"""Binary Sensor representing garages amsterdam data."""
|
"""Binary Sensor representing garages amsterdam data."""
|
||||||
|
|
||||||
|
_attr_attribution = ATTRIBUTION
|
||||||
|
_attr_device_class = BinarySensorDeviceClass.PROBLEM
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, coordinator: DataUpdateCoordinator, garage_name: str, info_type: str
|
self, coordinator: DataUpdateCoordinator, garage_name: str, info_type: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize garages amsterdam binary sensor."""
|
"""Initialize garages amsterdam binary sensor."""
|
||||||
super().__init__(coordinator)
|
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._garage_name = garage_name
|
||||||
self._info_type = info_type
|
self._info_type = info_type
|
||||||
self._name = garage_name
|
self._attr_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
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
|
@ -69,13 +59,3 @@ class GaragesamsterdamBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
||||||
return (
|
return (
|
||||||
getattr(self.coordinator.data[self._garage_name], self._info_type) != "ok"
|
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}
|
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
"""Sensor platform for Garages Amsterdam."""
|
"""Sensor platform for Garages Amsterdam."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
|
@ -48,25 +45,19 @@ async def async_setup_entry(
|
||||||
class GaragesamsterdamSensor(CoordinatorEntity, SensorEntity):
|
class GaragesamsterdamSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Sensor representing garages amsterdam data."""
|
"""Sensor representing garages amsterdam data."""
|
||||||
|
|
||||||
|
_attr_attribution = ATTRIBUTION
|
||||||
|
_attr_native_unit_of_measurement = "cars"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, coordinator: DataUpdateCoordinator, garage_name: str, info_type: str
|
self, coordinator: DataUpdateCoordinator, garage_name: str, info_type: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize garages amsterdam sensor."""
|
"""Initialize garages amsterdam sensor."""
|
||||||
super().__init__(coordinator)
|
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._garage_name = garage_name
|
||||||
self._info_type = info_type
|
self._info_type = info_type
|
||||||
self._name = f"{garage_name} - {info_type}".replace("_", " ")
|
self._attr_name = f"{garage_name} - {info_type}".replace("_", " ")
|
||||||
|
self._attr_icon = SENSORS[info_type]
|
||||||
@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
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
|
@ -79,18 +70,3 @@ class GaragesamsterdamSensor(CoordinatorEntity, SensorEntity):
|
||||||
def native_value(self) -> str:
|
def native_value(self) -> str:
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return getattr(self.coordinator.data[self._garage_name], self._info_type)
|
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}
|
|
||||||
|
|
Loading…
Reference in New Issue