From 205a2ee215d0c9539a430da85e2daf37ddbad476 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 29 Nov 2022 21:37:54 +0100 Subject: [PATCH] Ensure Abode provides valid device classes (#82929) --- homeassistant/components/abode/binary_sensor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/abode/binary_sensor.py b/homeassistant/components/abode/binary_sensor.py index 4f7af8af640..08ed1925936 100644 --- a/homeassistant/components/abode/binary_sensor.py +++ b/homeassistant/components/abode/binary_sensor.py @@ -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