Add more validation for mysensors (#5493)
* Move isdevice validator under helpers.config_validation. * Check that all persistence files are set and are unique if any is set by user. This is necessary to avoid file name clashes. * Check that a set persistence file has an existing and writable directory. * Check that a device is either a valid device file, "mqtt", or a valid domain name or ip address.
This commit is contained in:
parent
b57f5728c5
commit
a09a772f43
3 changed files with 61 additions and 20 deletions
|
@ -70,6 +70,15 @@ def boolean(value: Any) -> bool:
|
|||
return bool(value)
|
||||
|
||||
|
||||
def isdevice(value):
|
||||
"""Validate that value is a real device."""
|
||||
try:
|
||||
os.stat(value)
|
||||
return str(value)
|
||||
except OSError:
|
||||
raise vol.Invalid('No device at {} found'.format(value))
|
||||
|
||||
|
||||
def isfile(value: Any) -> str:
|
||||
"""Validate that the value is an existing file."""
|
||||
if value is None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue