| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- """
- Platform for Tuya Number options that don't fit into other entity types.
- """
- from homeassistant.components.number import NumberEntity
- from homeassistant.components.number.const import (
- DEFAULT_MIN_VALUE,
- DEFAULT_MAX_VALUE,
- )
- from ..device import TuyaLocalDevice
- from ..helpers.device_config import TuyaEntityConfig
- from ..helpers.mixin import TuyaLocalEntity
- MODE_AUTO = "auto"
- class TuyaLocalNumber(TuyaLocalEntity, NumberEntity):
- """Representation of a Tuya Number"""
- def __init__(self, device: TuyaLocalDevice, config: TuyaEntityConfig):
- """
- Initialise the sensor.
- Args:
- device (TuyaLocalDevice): the device API instance
- config (TuyaEntityConfig): the configuration for this entity
- """
- dps_map = self._init_begin(device, config)
- self._value_dps = dps_map.pop("value")
- if self._value_dps is None:
- raise AttributeError(f"{config.name} is missing a value dps")
- self._init_end(dps_map)
- @property
- def min_value(self):
- r = self._value_dps.range(self._device)
- return DEFAULT_MIN_VALUE if r is None else r["min"]
- @property
- def max_value(self):
- r = self._value_dps.range(self._device)
- return DEFAULT_MAX_VALUE if r is None else r["max"]
- @property
- def step(self):
- return self._value_dps.step(self._device)
- @property
- def mode(self):
- """Return the mode."""
- m = self._config.mode
- if m is None:
- m = MODE_AUTO
- return m
- @property
- def value(self):
- """Return the current value of the number."""
- return self._value_dps.get_value(self._device)
- async def async_set_value(self, value):
- """Set the number."""
- await self._value_dps.async_set_value(self._device, value)
|