1
mirror of https://github.com/home-assistant/core synced 2024-09-28 03:04:04 +02:00

Use shorthand device_type attr for plaato sensors (#100385)

This commit is contained in:
Jan Bouwhuis 2023-09-14 16:55:47 +02:00 committed by GitHub
parent d4a2927ebe
commit 89eec9990b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 22 deletions

View File

@ -39,20 +39,17 @@ async def async_setup_entry(
class PlaatoBinarySensor(PlaatoEntity, BinarySensorEntity):
"""Representation of a Binary Sensor."""
def __init__(self, data, sensor_type, coordinator=None) -> None:
"""Initialize plaato binary sensor."""
super().__init__(data, sensor_type, coordinator)
if sensor_type is PlaatoKeg.Pins.LEAK_DETECTION:
self._attr_device_class = BinarySensorDeviceClass.PROBLEM
elif sensor_type is PlaatoKeg.Pins.POURING:
self._attr_device_class = BinarySensorDeviceClass.OPENING
@property
def is_on(self):
"""Return true if the binary sensor is on."""
if self._coordinator is not None:
return self._coordinator.data.binary_sensors.get(self._sensor_type)
return False
@property
def device_class(self) -> BinarySensorDeviceClass | None:
"""Return the class of this device, from BinarySensorDeviceClass."""
if self._coordinator is None:
return None
if self._sensor_type is PlaatoKeg.Pins.LEAK_DETECTION:
return BinarySensorDeviceClass.PROBLEM
if self._sensor_type is PlaatoKeg.Pins.POURING:
return BinarySensorDeviceClass.OPENING
return None

View File

@ -72,17 +72,11 @@ async def async_setup_entry(
class PlaatoSensor(PlaatoEntity, SensorEntity):
"""Representation of a Plaato Sensor."""
@property
def device_class(self) -> SensorDeviceClass | None:
"""Return the class of this device, from SensorDeviceClass."""
if (
self._coordinator is not None
and self._sensor_type == PlaatoKeg.Pins.TEMPERATURE
):
return SensorDeviceClass.TEMPERATURE
if self._sensor_type == ATTR_TEMP:
return SensorDeviceClass.TEMPERATURE
return None
def __init__(self, data, sensor_type, coordinator=None) -> None:
"""Initialize plaato sensor."""
super().__init__(data, sensor_type, coordinator)
if sensor_type is PlaatoKeg.Pins.TEMPERATURE or sensor_type == ATTR_TEMP:
self._attr_device_class = SensorDeviceClass.TEMPERATURE
@property
def native_value(self):