Skip to content

Commit

Permalink
Fix issues in 10.2022 fix
Browse files Browse the repository at this point in the history
Refactored to new system
  • Loading branch information
veista committed Oct 9, 2022
1 parent 3436406 commit da69c47
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions custom_components/smartthings/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@

from homeassistant.components.number import NumberEntity, NumberMode

from homeassistant.components.sensor import SensorDeviceClass


from . import SmartThingsEntity
from .const import DATA_BROKERS, DOMAIN, UNIT_MAP

from homeassistant.const import PERCENTAGE, DEVICE_CLASS_TEMPERATURE
from homeassistant.const import PERCENTAGE

Map = namedtuple(
"map",
Expand Down Expand Up @@ -128,6 +131,7 @@ def __init__(
async def async_set_native_value(self, value: float) -> None:
"""Set the number value."""
await getattr(self._device, self._command)(int(value), set_status=True)
self.async_write_ha_state()

@property
def name(self) -> str:
Expand All @@ -152,23 +156,23 @@ def icon(self) -> str:
@property
def native_min_value(self) -> float:
"""Define mimimum level."""
return self._attr_min_value
return self._attr_native_min_value

@property
def native_max_value(self) -> float:
"""Define maximum level."""
return self._attr_max_value
return self._attr_native_max_value

@property
def native_step(self) -> float:
"""Define stepping size"""
return self._attr_step
return self._attr_native_step

@property
def native_unit_of_measurement(self) -> str | None:
"""Return unit of measurement"""
unit = self._device.status.attributes[self._attribute].unit
return UNIT_MAP.get(unit) if unit else self._attr_unit_of_measurement
return UNIT_MAP.get(unit) if unit else self._attr_native_unit_of_measurement

@property
def mode(self) -> Literal["auto", "slider", "box"]:
Expand Down Expand Up @@ -295,4 +299,4 @@ def mode(self) -> Literal["auto", "slider", "box"]:
@property
def device_class(self) -> str | None:
"""Return Device Class."""
return DEVICE_CLASS_TEMPERATURE
return SensorDeviceClass.TEMPERATURE

0 comments on commit da69c47

Please sign in to comment.