Create shortcuts for config entry parameters in Axis device (#45233)
parent
0b9687f7bd
commit
d80ef6c5fb
|
@ -11,7 +11,6 @@ from homeassistant.const import (
|
||||||
CONF_AUTHENTICATION,
|
CONF_AUTHENTICATION,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_PORT,
|
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
HTTP_DIGEST_AUTHENTICATION,
|
HTTP_DIGEST_AUTHENTICATION,
|
||||||
)
|
)
|
||||||
|
@ -41,9 +40,9 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
|
||||||
AxisEntityBase.__init__(self, device)
|
AxisEntityBase.__init__(self, device)
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
CONF_NAME: device.config_entry.data[CONF_NAME],
|
CONF_NAME: device.name,
|
||||||
CONF_USERNAME: device.config_entry.data[CONF_USERNAME],
|
CONF_USERNAME: device.username,
|
||||||
CONF_PASSWORD: device.config_entry.data[CONF_PASSWORD],
|
CONF_PASSWORD: device.password,
|
||||||
CONF_MJPEG_URL: self.mjpeg_source,
|
CONF_MJPEG_URL: self.mjpeg_source,
|
||||||
CONF_STILL_IMAGE_URL: self.image_source,
|
CONF_STILL_IMAGE_URL: self.image_source,
|
||||||
CONF_AUTHENTICATION: HTTP_DIGEST_AUTHENTICATION,
|
CONF_AUTHENTICATION: HTTP_DIGEST_AUTHENTICATION,
|
||||||
|
@ -78,7 +77,7 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
|
||||||
@property
|
@property
|
||||||
def image_source(self):
|
def image_source(self):
|
||||||
"""Return still image URL for device."""
|
"""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
|
@property
|
||||||
def mjpeg_source(self):
|
def mjpeg_source(self):
|
||||||
|
@ -87,7 +86,7 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
|
||||||
if self.device.option_stream_profile != DEFAULT_STREAM_PROFILE:
|
if self.device.option_stream_profile != DEFAULT_STREAM_PROFILE:
|
||||||
options = f"?&streamprofile={self.device.option_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):
|
async def stream_source(self):
|
||||||
"""Return the stream source."""
|
"""Return the stream source."""
|
||||||
|
@ -95,4 +94,4 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
|
||||||
if self.device.option_stream_profile != DEFAULT_STREAM_PROFILE:
|
if self.device.option_stream_profile != DEFAULT_STREAM_PROFILE:
|
||||||
options = f"&streamprofile={self.device.option_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}"
|
||||||
|
|
|
@ -60,9 +60,24 @@ class AxisNetworkDevice:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def host(self):
|
def host(self):
|
||||||
"""Return the host of this device."""
|
"""Return the host address of this device."""
|
||||||
return self.config_entry.data[CONF_HOST]
|
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
|
@property
|
||||||
def model(self):
|
def model(self):
|
||||||
"""Return the model of this device."""
|
"""Return the model of this device."""
|
||||||
|
@ -189,10 +204,10 @@ class AxisNetworkDevice:
|
||||||
try:
|
try:
|
||||||
self.api = await get_device(
|
self.api = await get_device(
|
||||||
self.hass,
|
self.hass,
|
||||||
host=self.config_entry.data[CONF_HOST],
|
host=self.host,
|
||||||
port=self.config_entry.data[CONF_PORT],
|
port=self.port,
|
||||||
username=self.config_entry.data[CONF_USERNAME],
|
username=self.username,
|
||||||
password=self.config_entry.data[CONF_PASSWORD],
|
password=self.password,
|
||||||
)
|
)
|
||||||
|
|
||||||
except CannotConnect as err:
|
except CannotConnect as err:
|
||||||
|
|
Loading…
Reference in New Issue