Use attr* in garages_amsterdam (#61605)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/61738/head
epenet 2021-12-13 23:16:13 +01:00 committed by GitHub
parent 905295707d
commit 85607970cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 56 deletions

View File

@ -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}

View File

@ -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}