Support configuring the mode of MQTT number entities (#77478)
* Support configuring the mode of MQTT number entities * Use modern schema for tests Co-authored-by: jbouwh <jan@jbsoft.nl>
This commit is contained in:
parent
cf5a11a1e7
commit
14717951c3
3 changed files with 82 additions and 1 deletions
|
@ -13,11 +13,13 @@ from homeassistant.components.number import (
|
|||
DEFAULT_STEP,
|
||||
DEVICE_CLASSES_SCHEMA,
|
||||
NumberDeviceClass,
|
||||
NumberMode,
|
||||
RestoreNumber,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE_CLASS,
|
||||
CONF_MODE,
|
||||
CONF_NAME,
|
||||
CONF_OPTIMISTIC,
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
|
@ -83,6 +85,7 @@ _PLATFORM_SCHEMA_BASE = MQTT_RW_SCHEMA.extend(
|
|||
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
|
||||
vol.Optional(CONF_MAX, default=DEFAULT_MAX_VALUE): vol.Coerce(float),
|
||||
vol.Optional(CONF_MIN, default=DEFAULT_MIN_VALUE): vol.Coerce(float),
|
||||
vol.Optional(CONF_MODE, default=NumberMode.AUTO): vol.Coerce(NumberMode),
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_OPTIMISTIC, default=DEFAULT_OPTIMISTIC): cv.boolean,
|
||||
vol.Optional(CONF_PAYLOAD_RESET, default=DEFAULT_PAYLOAD_RESET): cv.string,
|
||||
|
@ -276,6 +279,11 @@ class MqttNumber(MqttEntity, RestoreNumber):
|
|||
"""Return the current value."""
|
||||
return self._current_number
|
||||
|
||||
@property
|
||||
def mode(self) -> NumberMode:
|
||||
"""Return the mode of the entity."""
|
||||
return self._config[CONF_MODE]
|
||||
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Update the current value."""
|
||||
current_number = value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue