Ensure Abode provides valid device classes (#82929)

This commit is contained in:
Franck Nijhof 2022-11-29 21:37:54 +01:00 committed by GitHub
parent 368694d6bf
commit 205a2ee215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,7 @@
"""Support for Abode Security System binary sensors."""
from __future__ import annotations
from contextlib import suppress
from typing import cast
from abodepy.devices.binary_sensor import AbodeBinarySensor as ABBinarySensor
@ -47,8 +50,10 @@ class AbodeBinarySensor(AbodeDevice, BinarySensorEntity):
return cast(bool, self._device.is_on)
@property
def device_class(self) -> str:
def device_class(self) -> BinarySensorDeviceClass | None:
"""Return the class of the binary sensor."""
if self._device.get_value("is_window") == "1":
return BinarySensorDeviceClass.WINDOW
return cast(str, self._device.generic_type)
with suppress(ValueError):
return BinarySensorDeviceClass(cast(str, self._device.generic_type))
return None