Skip to content

Commit

Permalink
Add DeviceClass to NumberEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
stickpin committed Mar 1, 2024
1 parent 1cd6c1c commit 200672f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion custom_components/volkswagencarnet/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import logging
from typing import Union

from homeassistant.components.number import NumberEntity
from homeassistant.components.number import (
NumberEntity,
NumberDeviceClass,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory

Expand Down Expand Up @@ -74,6 +77,14 @@ def native_value(self) -> float:
return self.instrument.state
return None

@property
def device_class(self) -> Union[NumberDeviceClass, None]:
"""Return the device class."""
if self.instrument.device_class is None or self.instrument.device_class in NumberDeviceClass:
return self.instrument.device_class
_LOGGER.warning(f"Unknown device class {self.instrument.device_class}")
return None

@property
def entity_category(self) -> Union[EntityCategory, str, None]:
"""Return entity category."""
Expand Down

0 comments on commit 200672f

Please sign in to comment.