From 4c9303bbd5250f00edcd769693f43efbe7f4ee7c Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Fri, 20 Mar 2020 00:30:38 +0100 Subject: [PATCH] Axis - Fix char in stream url (#33004) * An unwanted character had found its way into a stream string, reverting f-string work to remove duplication of code and improve readability * Fix failing tests --- homeassistant/components/axis/camera.py | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/axis/camera.py b/homeassistant/components/axis/camera.py index 3cf84ce2288..c914319aa42 100644 --- a/homeassistant/components/axis/camera.py +++ b/homeassistant/components/axis/camera.py @@ -21,6 +21,10 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect from .axis_base import AxisEntityBase from .const import DOMAIN as AXIS_DOMAIN +AXIS_IMAGE = "http://{host}:{port}/axis-cgi/jpg/image.cgi" +AXIS_VIDEO = "http://{host}:{port}/axis-cgi/mjpg/video.cgi" +AXIS_STREAM = "rtsp://{user}:{password}@{host}/axis-media/media.amp?videocodec=h264" + async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Axis camera video stream.""" @@ -32,13 +36,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities): CONF_NAME: config_entry.data[CONF_NAME], CONF_USERNAME: config_entry.data[CONF_USERNAME], CONF_PASSWORD: config_entry.data[CONF_PASSWORD], - CONF_MJPEG_URL: ( - f"http://{config_entry.data[CONF_HOST]}" - f":{config_entry.data[CONF_PORT]}/axis-cgi/mjpg/video.cgi" + CONF_MJPEG_URL: AXIS_VIDEO.format( + host=config_entry.data[CONF_HOST], port=config_entry.data[CONF_PORT], ), - CONF_STILL_IMAGE_URL: ( - f"http://{config_entry.data[CONF_HOST]}" - f":{config_entry.data[CONF_PORT]}/axis-cgi/jpg/image.cgi" + CONF_STILL_IMAGE_URL: AXIS_IMAGE.format( + host=config_entry.data[CONF_HOST], port=config_entry.data[CONF_PORT], ), CONF_AUTHENTICATION: HTTP_DIGEST_AUTHENTICATION, } @@ -70,19 +72,17 @@ class AxisCamera(AxisEntityBase, MjpegCamera): async def stream_source(self): """Return the stream source.""" - return ( - f"rtsp://{self.device.config_entry.data[CONF_USERNAME]}ยด" - f":{self.device.config_entry.data[CONF_PASSWORD]}" - f"@{self.device.host}/axis-media/media.amp?videocodec=h264" + return AXIS_STREAM.format( + user=self.device.config_entry.data[CONF_USERNAME], + password=self.device.config_entry.data[CONF_PASSWORD], + host=self.device.host, ) def _new_address(self): """Set new device address for video stream.""" port = self.device.config_entry.data[CONF_PORT] - self._mjpeg_url = (f"http://{self.device.host}:{port}/axis-cgi/mjpg/video.cgi",) - self._still_image_url = ( - f"http://{self.device.host}:{port}/axis-cgi/jpg/image.cgi" - ) + self._mjpeg_url = AXIS_VIDEO.format(host=self.device.host, port=port) + self._still_image_url = AXIS_IMAGE.format(host=self.device.host, port=port) @property def unique_id(self):