Update Vivotek component stream source (#27941)

* Update Vivotek component

Fix building stream URL

* Update Vivotek component

Make stream path optionally configurable.

* Update Vivotek camera integration

Use f-string to build stream source URL.
This improve readability and I hear it runs faster.
pull/28517/head
Kevin McCormack 2019-11-03 22:11:14 -05:00 committed by Martin Hjelmare
parent 0973f1961d
commit cb2f42b336
1 changed files with 6 additions and 6 deletions

View File

@ -20,9 +20,12 @@ _LOGGER = logging.getLogger(__name__)
CONF_FRAMERATE = "framerate"
CONF_STREAM_PATH = "stream_path"
DEFAULT_CAMERA_BRAND = "Vivotek"
DEFAULT_NAME = "Vivotek Camera"
DEFAULT_EVENT_0_KEY = "event_i0_enable"
DEFAULT_STREAM_SOURCE = "live.sdp"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
@ -33,12 +36,14 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
vol.Optional(CONF_SSL, default=False): cv.boolean,
vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
vol.Optional(CONF_FRAMERATE, default=2): cv.positive_int,
vol.Optional(CONF_STREAM_PATH, default=DEFAULT_STREAM_SOURCE): cv.string,
}
)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up a Vivotek IP Camera."""
creds = f"{config[CONF_USERNAME]}:{config[CONF_PASSWORD]}"
args = dict(
config=config,
cam=VivotekCamera(
@ -48,12 +53,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
usr=config[CONF_USERNAME],
pwd=config[CONF_PASSWORD],
),
stream_source=(
"rtsp://%s:%s@%s:554/live.sdp",
config[CONF_USERNAME],
config[CONF_PASSWORD],
config[CONF_IP_ADDRESS],
),
stream_source=f"rtsp://{creds}@{config[CONF_IP_ADDRESS]}:554/{config[CONF_STREAM_PATH]}",
)
add_entities([VivotekCam(**args)], True)