Use try_parse_enum in integrations (#87085)

This commit is contained in:
epenet 2023-02-02 12:34:01 +01:00 committed by GitHub
parent 4a38b622b2
commit bd6a4d10ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 36 additions and 61 deletions

View file

@ -1,7 +1,6 @@
"""Support for esphome numbers."""
from __future__ import annotations
from contextlib import suppress
import math
from aioesphomeapi import NumberInfo, NumberMode as EsphomeNumberMode, NumberState
@ -10,6 +9,7 @@ from homeassistant.components.number import NumberDeviceClass, NumberEntity, Num
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.enum import try_parse_enum
from . import (
EsphomeEntity,
@ -51,9 +51,7 @@ class EsphomeNumber(EsphomeEntity[NumberInfo, NumberState], NumberEntity):
@property
def device_class(self) -> NumberDeviceClass | None:
"""Return the class of this entity."""
with suppress(ValueError):
return NumberDeviceClass(self._static_info.device_class)
return None
return try_parse_enum(NumberDeviceClass, self._static_info.device_class)
@property
def native_min_value(self) -> float: