Adds support for Pioneer AVR interface port number (#3878)
* Adds support for Pioneer AVR interface port number https://community.home-assistant.io/t/support-for-pioneer-avr/503 telnetlib supports a port number so adding port as an optional config element with a default of 23 resolves this. * Adds timeout to Pioneer AVR timeout in telnetlib defaults to socket._GLOBAL_DEFAULT_TIMEOUT which is not a value, but rather a bare Object used for comparison. telnetlib says the following about the timeout optional argument: "The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used)." From the documentation for sockets: "Sockets are by default always created in blocking mode" Catching connect and timeout errors, logging to debug and continuing. * Catches timeout exceptions, logs and continues.
This commit is contained in:
parent
ca6fa1313e
commit
57777ef79a
3 changed files with 76 additions and 10 deletions
|
@ -3,6 +3,7 @@ from collections import OrderedDict
|
|||
from datetime import timedelta
|
||||
import os
|
||||
from urllib.parse import urlparse
|
||||
from socket import _GLOBAL_DEFAULT_TIMEOUT
|
||||
|
||||
from typing import Any, Union, TypeVar, Callable, Sequence, Dict
|
||||
|
||||
|
@ -306,6 +307,24 @@ def time_zone(value):
|
|||
weekdays = vol.All(ensure_list, [vol.In(WEEKDAYS)])
|
||||
|
||||
|
||||
def socket_timeout(value):
|
||||
"""Validate timeout float > 0.0.
|
||||
|
||||
None coerced to socket._GLOBAL_DEFAULT_TIMEOUT bare object.
|
||||
"""
|
||||
if value is None:
|
||||
return _GLOBAL_DEFAULT_TIMEOUT
|
||||
else:
|
||||
try:
|
||||
float_value = float(value)
|
||||
if float_value > 0.0:
|
||||
return float_value
|
||||
raise vol.Invalid('Invalid socket timeout value.'
|
||||
' float > 0.0 required.')
|
||||
except Exception as _:
|
||||
raise vol.Invalid('Invalid socket timeout: {err}'.format(err=_))
|
||||
|
||||
|
||||
# pylint: disable=no-value-for-parameter
|
||||
def url(value: Any) -> str:
|
||||
"""Validate an URL."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue