Improve Axis integration (#36205)
* Improve configuration * Read new properties for basic device information Improve tests by mocking less improving stability of tests * Clean up in device tests * Support new port management api * Improve initializing data * Bump dependency to v28
This commit is contained in:
1 parent
6ed68d8ced
commit
01d9366299
10 files changed
+215
-152
No files matched your search
@@ -27,7 +27,7 @@ async def async_setup_entry(hass, config_entry):
|
||||
# 0.104 introduced config entry unique id, this makes upgrading possible
|
||||
if config_entry.unique_id is None:
|
||||
hass.config_entries.async_update_entry(
|
||||
config_entry, unique_id=device.api.vapix.params.system_serialnumber
|
||||
config_entry, unique_id=device.api.vapix.serial_number
|
||||
)
|
||||
|
||||
hass.data[AXIS_DOMAIN][config_entry.unique_id] = device
|
||||
|
||||
@@ -61,8 +61,7 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
password=user_input[CONF_PASSWORD],
|
||||
)
|
||||
|
||||
serial_number = device.vapix.params.system_serialnumber
|
||||
await self.async_set_unique_id(serial_number)
|
||||
await self.async_set_unique_id(device.vapix.serial_number)
|
||||
|
||||
self._abort_if_unique_id_configured(
|
||||
updates={
|
||||
@@ -76,8 +75,8 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
CONF_PORT: user_input[CONF_PORT],
|
||||
CONF_USERNAME: user_input[CONF_USERNAME],
|
||||
CONF_PASSWORD: user_input[CONF_PASSWORD],
|
||||
CONF_MAC: serial_number,
|
||||
CONF_MODEL: device.vapix.params.prodnbr,
|
||||
CONF_MAC: device.vapix.serial_number,
|
||||
CONF_MODEL: device.vapix.product_number,
|
||||
}
|
||||
|
||||
return await self._create_entry()
|
||||
|
||||
@@ -4,6 +4,7 @@ import asyncio
|
||||
|
||||
import async_timeout
|
||||
import axis
|
||||
from axis.configuration import Configuration
|
||||
from axis.event_stream import OPERATION_INITIALIZED
|
||||
from axis.mqtt import mqtt_json_to_event
|
||||
from axis.streammanager import SIGNAL_PLAYING, STATE_STOPPED
|
||||
@@ -185,8 +186,8 @@ class AxisNetworkDevice:
|
||||
LOGGER.error("Unknown error connecting with Axis device on %s", self.host)
|
||||
return False
|
||||
|
||||
self.fw_version = self.api.vapix.params.firmware_version
|
||||
self.product_type = self.api.vapix.params.prodtype
|
||||
self.fw_version = self.api.vapix.firmware_version
|
||||
self.product_type = self.api.vapix.product_type
|
||||
|
||||
async def start_platforms():
|
||||
await asyncio.gather(
|
||||
@@ -254,22 +255,12 @@ async def get_device(hass, host, port, username, password):
|
||||
"""Create a Axis device."""
|
||||
|
||||
device = axis.AxisDevice(
|
||||
host=host, port=port, username=username, password=password, web_proto="http",
|
||||
Configuration(host, port=port, username=username, password=password)
|
||||
)
|
||||
|
||||
device.vapix.initialize_params(preload_data=False)
|
||||
device.vapix.initialize_ports()
|
||||
|
||||
try:
|
||||
with async_timeout.timeout(15):
|
||||
|
||||
for vapix_call in (
|
||||
device.vapix.initialize_api_discovery,
|
||||
device.vapix.params.update_brand,
|
||||
device.vapix.params.update_properties,
|
||||
device.vapix.ports.update,
|
||||
):
|
||||
await hass.async_add_executor_job(vapix_call)
|
||||
await hass.async_add_executor_job(device.vapix.initialize)
|
||||
|
||||
return device
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "Axis",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/axis",
|
||||
"requirements": ["axis==27"],
|
||||
"requirements": ["axis==28"],
|
||||
"zeroconf": ["_axis-video._tcp.local."],
|
||||
"after_dependencies": ["mqtt"],
|
||||
"codeowners": ["@Kane610"]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Support for Axis switches."""
|
||||
|
||||
from axis.event_stream import CLASS_OUTPUT
|
||||
from axis.port_cgi import ACTION_HIGH, ACTION_LOW
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.core import callback
|
||||
@@ -39,13 +38,13 @@ class AxisSwitch(AxisEventBase, SwitchEntity):
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn on switch."""
|
||||
await self.hass.async_add_executor_job(
|
||||
self.device.api.vapix.ports[self.event.id].action, ACTION_HIGH
|
||||
self.device.api.vapix.ports[self.event.id].close
|
||||
)
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn off switch."""
|
||||
await self.hass.async_add_executor_job(
|
||||
self.device.api.vapix.ports[self.event.id].action, ACTION_LOW
|
||||
self.device.api.vapix.ports[self.event.id].open
|
||||
)
|
||||
|
||||
@property
|
||||
|
||||
Reference in new issue
Block a user