Use enums in plaato (#62069)

* Use enums in plaato

* uno mas

* uno mas
This commit is contained in:
Robert Hillis 2021-12-16 10:00:22 -05:00 committed by GitHub
parent 7c8d235356
commit 16d16585ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -1,10 +1,10 @@
"""Support for Plaato Airlock sensors."""
from __future__ import annotations
from pyplaato.plaato import PlaatoKeg
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_OPENING,
DEVICE_CLASS_PROBLEM,
BinarySensorDeviceClass,
BinarySensorEntity,
)
@ -40,11 +40,11 @@ class PlaatoBinarySensor(PlaatoEntity, BinarySensorEntity):
return False
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
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 DEVICE_CLASS_PROBLEM
return BinarySensorDeviceClass.PROBLEM
if self._sensor_type is PlaatoKeg.Pins.POURING:
return DEVICE_CLASS_OPENING
return BinarySensorDeviceClass.OPENING

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from pyplaato.models.device import PlaatoDevice
from pyplaato.plaato import PlaatoKeg
from homeassistant.components.sensor import DEVICE_CLASS_TEMPERATURE, SensorEntity
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
@ -63,15 +63,15 @@ class PlaatoSensor(PlaatoEntity, SensorEntity):
"""Representation of a Plaato Sensor."""
@property
def device_class(self) -> str | None:
"""Return the class of this device, from component DEVICE_CLASSES."""
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 DEVICE_CLASS_TEMPERATURE
return SensorDeviceClass.TEMPERATURE
if self._sensor_type == ATTR_TEMP:
return DEVICE_CLASS_TEMPERATURE
return SensorDeviceClass.TEMPERATURE
return None
@property