Create shortcuts for config entry parameters in Axis device (#45233)

pull/45277/head
Robert Svensson 2021-01-16 19:54:48 +01:00 committed by GitHub
parent 0b9687f7bd
commit d80ef6c5fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 12 deletions

View File

@ -11,7 +11,6 @@ from homeassistant.const import (
CONF_AUTHENTICATION,
CONF_NAME,
CONF_PASSWORD,
CONF_PORT,
CONF_USERNAME,
HTTP_DIGEST_AUTHENTICATION,
)
@ -41,9 +40,9 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
AxisEntityBase.__init__(self, device)
config = {
CONF_NAME: device.config_entry.data[CONF_NAME],
CONF_USERNAME: device.config_entry.data[CONF_USERNAME],
CONF_PASSWORD: device.config_entry.data[CONF_PASSWORD],
CONF_NAME: device.name,
CONF_USERNAME: device.username,
CONF_PASSWORD: device.password,
CONF_MJPEG_URL: self.mjpeg_source,
CONF_STILL_IMAGE_URL: self.image_source,
CONF_AUTHENTICATION: HTTP_DIGEST_AUTHENTICATION,
@ -78,7 +77,7 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
@property
def image_source(self):
"""Return still image URL for device."""
return f"http://{self.device.host}:{self.device.config_entry.data[CONF_PORT]}/axis-cgi/jpg/image.cgi"
return f"http://{self.device.host}:{self.device.port}/axis-cgi/jpg/image.cgi"
@property
def mjpeg_source(self):
@ -87,7 +86,7 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
if self.device.option_stream_profile != DEFAULT_STREAM_PROFILE:
options = f"?&streamprofile={self.device.option_stream_profile}"
return f"http://{self.device.host}:{self.device.config_entry.data[CONF_PORT]}/axis-cgi/mjpg/video.cgi{options}"
return f"http://{self.device.host}:{self.device.port}/axis-cgi/mjpg/video.cgi{options}"
async def stream_source(self):
"""Return the stream source."""
@ -95,4 +94,4 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
if self.device.option_stream_profile != DEFAULT_STREAM_PROFILE:
options = f"&streamprofile={self.device.option_stream_profile}"
return f"rtsp://{self.device.config_entry.data[CONF_USERNAME]}:{self.device.config_entry.data[CONF_PASSWORD]}@{self.device.host}/axis-media/media.amp?videocodec=h264{options}"
return f"rtsp://{self.device.username}:{self.device.password}@{self.device.host}/axis-media/media.amp?videocodec=h264{options}"

View File

@ -60,9 +60,24 @@ class AxisNetworkDevice:
@property
def host(self):
"""Return the host of this device."""
"""Return the host address of this device."""
return self.config_entry.data[CONF_HOST]
@property
def port(self):
"""Return the HTTP port of this device."""
return self.config_entry.data[CONF_PORT]
@property
def username(self):
"""Return the username of this device."""
return self.config_entry.data[CONF_USERNAME]
@property
def password(self):
"""Return the password of this device."""
return self.config_entry.data[CONF_PASSWORD]
@property
def model(self):
"""Return the model of this device."""
@ -189,10 +204,10 @@ class AxisNetworkDevice:
try:
self.api = await get_device(
self.hass,
host=self.config_entry.data[CONF_HOST],
port=self.config_entry.data[CONF_PORT],
username=self.config_entry.data[CONF_USERNAME],
password=self.config_entry.data[CONF_PASSWORD],
host=self.host,
port=self.port,
username=self.username,
password=self.password,
)
except CannotConnect as err: