mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Added password mode to input_text (obscure content of text box) (#11849)
* Round values to one decimal Temperature detection range: -20 - 60 Deg.C ( + / - 0.3 Deg.C ) Humidity detection range: 0 - 100pct RH ( + / - 0.3pct ) Atmospheric pressure detection range: 30 - 110KPa ( + / - 120Pa ) * Add password mode option Hide the content of the input_text field * Revert "Round values to one decimal" This reverts commit a3124a6aaa2261eff558e2bd37a3eda57d1aac71. * Added test for mode option * Added newline (lint)
This commit is contained in:
parent
25cbc8317f
commit
905bb36e6a
@ -11,7 +11,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID, ATTR_UNIT_OF_MEASUREMENT, CONF_ICON, CONF_NAME)
|
ATTR_ENTITY_ID, ATTR_UNIT_OF_MEASUREMENT, CONF_ICON, CONF_NAME, CONF_MODE)
|
||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
@ -26,10 +26,14 @@ CONF_INITIAL = 'initial'
|
|||||||
CONF_MIN = 'min'
|
CONF_MIN = 'min'
|
||||||
CONF_MAX = 'max'
|
CONF_MAX = 'max'
|
||||||
|
|
||||||
|
MODE_TEXT = 'text'
|
||||||
|
MODE_PASSWORD = 'password'
|
||||||
|
|
||||||
ATTR_VALUE = 'value'
|
ATTR_VALUE = 'value'
|
||||||
ATTR_MIN = 'min'
|
ATTR_MIN = 'min'
|
||||||
ATTR_MAX = 'max'
|
ATTR_MAX = 'max'
|
||||||
ATTR_PATTERN = 'pattern'
|
ATTR_PATTERN = 'pattern'
|
||||||
|
ATTR_MODE = 'mode'
|
||||||
|
|
||||||
SERVICE_SET_VALUE = 'set_value'
|
SERVICE_SET_VALUE = 'set_value'
|
||||||
|
|
||||||
@ -63,6 +67,8 @@ CONFIG_SCHEMA = vol.Schema({
|
|||||||
vol.Optional(CONF_ICON): cv.icon,
|
vol.Optional(CONF_ICON): cv.icon,
|
||||||
vol.Optional(ATTR_UNIT_OF_MEASUREMENT): cv.string,
|
vol.Optional(ATTR_UNIT_OF_MEASUREMENT): cv.string,
|
||||||
vol.Optional(ATTR_PATTERN): cv.string,
|
vol.Optional(ATTR_PATTERN): cv.string,
|
||||||
|
vol.Optional(CONF_MODE, default=MODE_TEXT):
|
||||||
|
vol.In([MODE_TEXT, MODE_PASSWORD]),
|
||||||
}, _cv_input_text)
|
}, _cv_input_text)
|
||||||
})
|
})
|
||||||
}, required=True, extra=vol.ALLOW_EXTRA)
|
}, required=True, extra=vol.ALLOW_EXTRA)
|
||||||
@ -92,10 +98,11 @@ def async_setup(hass, config):
|
|||||||
icon = cfg.get(CONF_ICON)
|
icon = cfg.get(CONF_ICON)
|
||||||
unit = cfg.get(ATTR_UNIT_OF_MEASUREMENT)
|
unit = cfg.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||||
pattern = cfg.get(ATTR_PATTERN)
|
pattern = cfg.get(ATTR_PATTERN)
|
||||||
|
mode = cfg.get(CONF_MODE)
|
||||||
|
|
||||||
entities.append(InputText(
|
entities.append(InputText(
|
||||||
object_id, name, initial, minimum, maximum, icon, unit,
|
object_id, name, initial, minimum, maximum, icon, unit,
|
||||||
pattern))
|
pattern, mode))
|
||||||
|
|
||||||
if not entities:
|
if not entities:
|
||||||
return False
|
return False
|
||||||
@ -122,7 +129,7 @@ class InputText(Entity):
|
|||||||
"""Represent a text box."""
|
"""Represent a text box."""
|
||||||
|
|
||||||
def __init__(self, object_id, name, initial, minimum, maximum, icon,
|
def __init__(self, object_id, name, initial, minimum, maximum, icon,
|
||||||
unit, pattern):
|
unit, pattern, mode):
|
||||||
"""Initialize a text input."""
|
"""Initialize a text input."""
|
||||||
self.entity_id = ENTITY_ID_FORMAT.format(object_id)
|
self.entity_id = ENTITY_ID_FORMAT.format(object_id)
|
||||||
self._name = name
|
self._name = name
|
||||||
@ -132,6 +139,7 @@ class InputText(Entity):
|
|||||||
self._icon = icon
|
self._icon = icon
|
||||||
self._unit = unit
|
self._unit = unit
|
||||||
self._pattern = pattern
|
self._pattern = pattern
|
||||||
|
self._mode = mode
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
@ -165,6 +173,7 @@ class InputText(Entity):
|
|||||||
ATTR_MIN: self._minimum,
|
ATTR_MIN: self._minimum,
|
||||||
ATTR_MAX: self._maximum,
|
ATTR_MAX: self._maximum,
|
||||||
ATTR_PATTERN: self._pattern,
|
ATTR_PATTERN: self._pattern,
|
||||||
|
ATTR_MODE: self._mode,
|
||||||
}
|
}
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -64,6 +64,41 @@ class TestInputText(unittest.TestCase):
|
|||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual('testing', str(state.state))
|
self.assertEqual('testing', str(state.state))
|
||||||
|
|
||||||
|
def test_mode(self):
|
||||||
|
"""Test mode settings."""
|
||||||
|
self.assertTrue(
|
||||||
|
setup_component(self.hass, DOMAIN, {DOMAIN: {
|
||||||
|
'test_default_text': {
|
||||||
|
'initial': 'test',
|
||||||
|
'min': 3,
|
||||||
|
'max': 10,
|
||||||
|
},
|
||||||
|
'test_explicit_text': {
|
||||||
|
'initial': 'test',
|
||||||
|
'min': 3,
|
||||||
|
'max': 10,
|
||||||
|
'mode': 'text',
|
||||||
|
},
|
||||||
|
'test_explicit_password': {
|
||||||
|
'initial': 'test',
|
||||||
|
'min': 3,
|
||||||
|
'max': 10,
|
||||||
|
'mode': 'password',
|
||||||
|
},
|
||||||
|
}}))
|
||||||
|
|
||||||
|
state = self.hass.states.get('input_text.test_default_text')
|
||||||
|
assert state
|
||||||
|
self.assertEqual('text', state.attributes['mode'])
|
||||||
|
|
||||||
|
state = self.hass.states.get('input_text.test_explicit_text')
|
||||||
|
assert state
|
||||||
|
self.assertEqual('text', state.attributes['mode'])
|
||||||
|
|
||||||
|
state = self.hass.states.get('input_text.test_explicit_password')
|
||||||
|
assert state
|
||||||
|
self.assertEqual('password', state.attributes['mode'])
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_restore_state(hass):
|
def test_restore_state(hass):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user