init home-assistant
This commit is contained in:
57
home-assistant/tests/components/elmax/__init__.py
Normal file
57
home-assistant/tests/components/elmax/__init__.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""Tests for the Elmax component."""
|
||||
|
||||
from homeassistant.components.elmax.const import (
|
||||
CONF_ELMAX_MODE,
|
||||
CONF_ELMAX_MODE_DIRECT,
|
||||
CONF_ELMAX_MODE_DIRECT_HOST,
|
||||
CONF_ELMAX_MODE_DIRECT_PORT,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL_CERT,
|
||||
CONF_ELMAX_PANEL_ID,
|
||||
CONF_ELMAX_PANEL_PIN,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
MOCK_USER_JWT = (
|
||||
"JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
|
||||
".eyJfaWQiOiIxYjExYmIxMWJiYjExMTExYjFiMTFiMWIiLCJlbWFpbCI6InRoaXMuaXNAdGVzdC5jb20iLCJyb2xlIjoid"
|
||||
"XNlciIsImlhdCI6MTYzNjE5OTk5OCwiZXhwIjoxNjM2MjM1OTk4fQ.1C7lXuKyX1HEGOfMxNwxJ2n-CjoW4rwvNRITQxLI"
|
||||
"Cv0"
|
||||
)
|
||||
MOCK_USERNAME = "this.is@test.com"
|
||||
MOCK_USER_ROLE = "user"
|
||||
MOCK_USER_ID = "1b11bb11bbb11111b1b11b1b"
|
||||
MOCK_PANEL_ID = "2db3dae30b9102de4d078706f94d0708"
|
||||
MOCK_PANEL_NAME = "Test Panel Name"
|
||||
MOCK_PANEL_PIN = "000000"
|
||||
MOCK_WRONG_PANEL_PIN = "000000"
|
||||
MOCK_PASSWORD = "password"
|
||||
MOCK_DIRECT_HOST = "1.1.1.1"
|
||||
MOCK_DIRECT_HOST_CHANGED = "2.2.2.2"
|
||||
MOCK_DIRECT_PORT = 443
|
||||
MOCK_DIRECT_SSL = True
|
||||
MOCK_DIRECT_CERT = load_fixture("direct/cert.pem", "elmax")
|
||||
MOCK_DIRECT_FOLLOW_MDNS = True
|
||||
|
||||
|
||||
async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
|
||||
"""Mock integration setup."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_ELMAX_MODE: CONF_ELMAX_MODE_DIRECT,
|
||||
CONF_ELMAX_MODE_DIRECT_HOST: MOCK_DIRECT_HOST,
|
||||
CONF_ELMAX_MODE_DIRECT_PORT: MOCK_DIRECT_PORT,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL: MOCK_DIRECT_SSL,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
CONF_ELMAX_PANEL_ID: None,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL_CERT: MOCK_DIRECT_CERT,
|
||||
},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
return entry
|
||||
102
home-assistant/tests/components/elmax/conftest.py
Normal file
102
home-assistant/tests/components/elmax/conftest.py
Normal file
@@ -0,0 +1,102 @@
|
||||
"""Configuration for Elmax tests."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from elmax_api.constants import (
|
||||
BASE_URL,
|
||||
ENDPOINT_DEVICES,
|
||||
ENDPOINT_DISCOVERY,
|
||||
ENDPOINT_LOGIN,
|
||||
)
|
||||
from httpx import Response
|
||||
import jwt
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from . import (
|
||||
MOCK_DIRECT_HOST,
|
||||
MOCK_DIRECT_PORT,
|
||||
MOCK_DIRECT_SSL,
|
||||
MOCK_PANEL_ID,
|
||||
MOCK_PANEL_PIN,
|
||||
)
|
||||
|
||||
from tests.common import load_fixture
|
||||
|
||||
MOCK_DIRECT_BASE_URI = (
|
||||
f"{'https' if MOCK_DIRECT_SSL else 'http'}://{MOCK_DIRECT_HOST}:{MOCK_DIRECT_PORT}"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def httpx_mock_cloud_fixture() -> Generator[respx.MockRouter]:
|
||||
"""Configure httpx fixture for cloud API communication."""
|
||||
with respx.mock(base_url=BASE_URL, assert_all_called=False) as respx_mock:
|
||||
# Mock Login POST.
|
||||
login_route = respx_mock.post(f"/{ENDPOINT_LOGIN}", name="login")
|
||||
login_route.return_value = Response(
|
||||
200, json=json.loads(load_fixture("cloud/login.json", "elmax"))
|
||||
)
|
||||
|
||||
# Mock Device list GET.
|
||||
list_devices_route = respx_mock.get(f"/{ENDPOINT_DEVICES}", name="list_devices")
|
||||
list_devices_route.return_value = Response(
|
||||
200, json=json.loads(load_fixture("cloud/list_devices.json", "elmax"))
|
||||
)
|
||||
|
||||
# Mock Panel GET.
|
||||
get_panel_route = respx_mock.get(
|
||||
f"/{ENDPOINT_DISCOVERY}/{MOCK_PANEL_ID}/{MOCK_PANEL_PIN}", name="get_panel"
|
||||
)
|
||||
get_panel_route.return_value = Response(
|
||||
200, json=json.loads(load_fixture("cloud/get_panel.json", "elmax"))
|
||||
)
|
||||
|
||||
yield respx_mock
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def httpx_mock_direct_fixture() -> Generator[respx.MockRouter]:
|
||||
"""Configure httpx fixture for direct Panel-API communication."""
|
||||
with respx.mock(
|
||||
base_url=MOCK_DIRECT_BASE_URI, assert_all_called=False
|
||||
) as respx_mock:
|
||||
# Mock Login POST.
|
||||
login_route = respx_mock.post(f"/api/v2/{ENDPOINT_LOGIN}", name="login")
|
||||
|
||||
login_json = json.loads(load_fixture("direct/login.json", "elmax"))
|
||||
decoded_jwt = jwt.decode_complete(
|
||||
login_json["token"].split(" ")[1],
|
||||
algorithms="HS256",
|
||||
options={"verify_signature": False},
|
||||
)
|
||||
expiration = datetime.now() + timedelta(hours=1)
|
||||
decoded_jwt["payload"]["exp"] = int(expiration.timestamp())
|
||||
jws_string = jwt.encode(
|
||||
payload=decoded_jwt["payload"], algorithm="HS256", key=""
|
||||
)
|
||||
login_json["token"] = f"JWT {jws_string}"
|
||||
login_route.return_value = Response(200, json=login_json)
|
||||
|
||||
# Mock Device list GET.
|
||||
list_devices_route = respx_mock.get(
|
||||
f"/api/v2/{ENDPOINT_DISCOVERY}", name="discovery_panel"
|
||||
)
|
||||
list_devices_route.return_value = Response(
|
||||
200, json=json.loads(load_fixture("direct/discovery_panel.json", "elmax"))
|
||||
)
|
||||
|
||||
yield respx_mock
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def elmax_mock_direct_cert() -> Generator[AsyncMock]:
|
||||
"""Patch elmax library to return a specific PEM for SSL communication."""
|
||||
with patch(
|
||||
"elmax_api.http.GenericElmax.retrieve_server_certificate",
|
||||
return_value=load_fixture("direct/cert.pem", "elmax"),
|
||||
) as patched_ssl_get_cert:
|
||||
yield patched_ssl_get_cert
|
||||
@@ -0,0 +1,126 @@
|
||||
{
|
||||
"release": 11.7,
|
||||
"tappFeature": true,
|
||||
"sceneFeature": true,
|
||||
"zone": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-zona-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"nome": "Feed zone 0",
|
||||
"aperta": false,
|
||||
"esclusa": false
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-zona-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"nome": "Feed Zone 1",
|
||||
"aperta": false,
|
||||
"esclusa": false
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-zona-2",
|
||||
"visibile": true,
|
||||
"indice": 2,
|
||||
"nome": "Feed Zone 2",
|
||||
"aperta": false,
|
||||
"esclusa": false
|
||||
}
|
||||
],
|
||||
"uscite": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-uscita-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"nome": "Actuator 0",
|
||||
"aperta": false
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-uscita-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"nome": "Actuator 1",
|
||||
"aperta": false
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-uscita-2",
|
||||
"visibile": true,
|
||||
"indice": 2,
|
||||
"nome": "Actuator 2",
|
||||
"aperta": true
|
||||
}
|
||||
],
|
||||
"aree": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-area-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"nome": "AREA 0",
|
||||
"statiDisponibili": [0, 1, 2, 3, 4],
|
||||
"statiSessioneDisponibili": [0, 1, 2, 3],
|
||||
"stato": 0,
|
||||
"statoSessione": 0
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-area-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"nome": "AREA 1",
|
||||
"statiDisponibili": [0, 1, 2, 3, 4],
|
||||
"statiSessioneDisponibili": [0, 1, 2, 3],
|
||||
"stato": 0,
|
||||
"statoSessione": 0
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-area-2",
|
||||
"visibile": false,
|
||||
"indice": 2,
|
||||
"nome": "AREA 2",
|
||||
"statiDisponibili": [0, 1, 2, 3, 4],
|
||||
"statiSessioneDisponibili": [0, 1, 2, 3],
|
||||
"stato": 0,
|
||||
"statoSessione": 0
|
||||
}
|
||||
],
|
||||
"tapparelle": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-tapparella-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"stato": "stop",
|
||||
"posizione": 100,
|
||||
"nome": "Cover 0"
|
||||
}
|
||||
],
|
||||
"gruppi": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-gruppo-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"nome": "Group 0"
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-gruppo-1",
|
||||
"visibile": false,
|
||||
"indice": 1,
|
||||
"nome": "Group 1"
|
||||
}
|
||||
],
|
||||
"scenari": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-scenario-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"nome": "Automation 0"
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-scenario-2",
|
||||
"visibile": true,
|
||||
"indice": 2,
|
||||
"nome": "Automation 2"
|
||||
}
|
||||
],
|
||||
"utente": "this.is@test.com",
|
||||
"centrale": "2db3dae30b9102de4d078706f94d0708"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"centrale_online": true,
|
||||
"hash": "2db3dae30b9102de4d078706f94d0708",
|
||||
"username": [{ "name": "this.is@test.com", "label": "Test Panel Name" }]
|
||||
},
|
||||
{
|
||||
"centrale_online": true,
|
||||
"hash": "d8e8fca2dc0f896fd7cb4cb0031ba249",
|
||||
"username": [{ "name": "this.is@test.com", "label": "Test Panel Name" }]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"token": "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiIxYjExYmIxMWJiYjExMTExYjFiMTFiMWIiLCJlbWFpbCI6InRoaXMuaXNAdGVzdC5jb20iLCJyb2xlIjoidXNlciIsImlhdCI6MTYzNjE5OTk5OCwiZXhwIjoxNjM2MjM1OTk4fQ.1C7lXuKyX1HEGOfMxNwxJ2n-CjoW4rwvNRITQxLICv0",
|
||||
"user": {
|
||||
"_id": "1b11bb11bbb11111b1b11b1b",
|
||||
"email": "this.is@test.com",
|
||||
"role": "user"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDozCCAougAwIBAgIUQw+nCBfAnisI86E/KS24OpJl6oQwDQYJKoZIhvcNAQEL
|
||||
BQAwYTELMAkGA1UEBhMCSVQxDzANBgNVBAgMBk1pbGFubzEPMA0GA1UEBwwGTWls
|
||||
YW5vMRcwFQYDVQQKDA5BbGJlcnRvR2VuaW9sYTEXMBUGA1UEAwwOYWxiZXJ0b2dl
|
||||
bmlvbGEwHhcNMjIxMTEyMTc1MzE0WhcNMjMxMTEyMTc1MzE0WjBhMQswCQYDVQQG
|
||||
EwJJVDEPMA0GA1UECAwGTWlsYW5vMQ8wDQYDVQQHDAZNaWxhbm8xFzAVBgNVBAoM
|
||||
DkFsYmVydG9HZW5pb2xhMRcwFQYDVQQDDA5hbGJlcnRvZ2VuaW9sYTCCASIwDQYJ
|
||||
KoZIhvcNAQEBBQADggEPADCCAQoCggEBAKKlyvbpb3IqrKsmNe3WLscXWOm1zWuZ
|
||||
OECukWl9NFep1v7H2VgH8Vc5/Lz8GyFIK6f4auq3E8Cv3AuDH3Z9q8sxN4E4vh6Q
|
||||
zkFqyBa4yAXyaN6AT/ZgmZTbd4KUg+AHecGeDdedbDRc7s8bPDILcQM/S49RSnnS
|
||||
IYivDnf3uByCPjvU2+/JRUvrB+rlL3tvUt/H+In8uRd01cBAx3GQLN/eqmkgUhiy
|
||||
/eI3r7g5goxyCZpy6uyQEfN1CYWOpoIdL9rAEwwvrT+zK7iPqxCN3N0xQNvVpNzE
|
||||
ifTONUPq+JPxO0SIP3Ro7rSeNSoe1O309qb7kpi5G/Zt7u3nRoiL1zUCAwEAAaNT
|
||||
MFEwHQYDVR0OBBYEFIceFAyZ62kgZZqVJ4cLQCMbproRMB8GA1UdIwQYMBaAFIce
|
||||
FAyZ62kgZZqVJ4cLQCMbproRMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL
|
||||
BQADggEBACHt8GY2FAruQ4Xa1JIMFHzGsqW8OMg6M1Ntrclu7MmST7T35VyCzBfB
|
||||
QUwasn8bp/XHTZSmJB8RndYRKslATHSMyWhqjGCBNoSI8ljJgn9YLopRnAwEKQ6P
|
||||
sqRl6/uMhwC587nIG1GJGWx2SbxrqoTcy39QmK0vHZfCVctzREZLaWGI2rtiQkVZ
|
||||
mt3A0aQck+KQPlCIac14Z6lZJLJ4wSq6x7gjQAFA9uQfbnTaerOGgDTnhwsIrON3
|
||||
TkSZ0dFgvt3lnbpO7fa8nPhdKFgzWZzymAjv3vsAxiboDE3LPn9BulxEkC+IFf5Q
|
||||
6n+BK6Ogu16GZX4zUKeVdF089opux64=
|
||||
-----END CERTIFICATE-----
|
||||
@@ -0,0 +1,148 @@
|
||||
{
|
||||
"release": "PHANTOM64PRO_GSM 11.9.844",
|
||||
"tappFeature": true,
|
||||
"sceneFeature": true,
|
||||
"zone": [
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-zona-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"aperta": true,
|
||||
"esclusa": false,
|
||||
"nome": "ZONA 01"
|
||||
},
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-zona-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"aperta": true,
|
||||
"esclusa": false,
|
||||
"nome": "ZONA 02e"
|
||||
},
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-zona-2",
|
||||
"visibile": true,
|
||||
"indice": 2,
|
||||
"aperta": true,
|
||||
"esclusa": false,
|
||||
"nome": "ZONA 03a"
|
||||
},
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-zona-3",
|
||||
"visibile": true,
|
||||
"indice": 3,
|
||||
"aperta": true,
|
||||
"esclusa": false,
|
||||
"nome": "ZONA 04"
|
||||
},
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-zona-4",
|
||||
"visibile": true,
|
||||
"indice": 4,
|
||||
"aperta": true,
|
||||
"esclusa": false,
|
||||
"nome": "ZONA 05"
|
||||
},
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-zona-5",
|
||||
"visibile": true,
|
||||
"indice": 5,
|
||||
"aperta": true,
|
||||
"esclusa": false,
|
||||
"nome": "ZONA 06"
|
||||
},
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-zona-6",
|
||||
"visibile": true,
|
||||
"indice": 6,
|
||||
"aperta": true,
|
||||
"esclusa": false,
|
||||
"nome": "ZONA 07"
|
||||
},
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-zona-7",
|
||||
"visibile": true,
|
||||
"indice": 7,
|
||||
"aperta": true,
|
||||
"esclusa": false,
|
||||
"nome": "ZONA 08"
|
||||
}
|
||||
],
|
||||
"uscite": [
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-uscita-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"aperta": true,
|
||||
"nome": "USCITA 02"
|
||||
}
|
||||
],
|
||||
"aree": [
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-area-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"statiDisponibili": [0, 1, 2, 3, 4],
|
||||
"statiSessioneDisponibili": [0, 1, 2, 3],
|
||||
"stato": 0,
|
||||
"statoSessione": 1,
|
||||
"zoneBmask": "0700000000000000",
|
||||
"nome": "AREA 1"
|
||||
},
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-area-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"statiDisponibili": [0, 1, 2, 3, 4],
|
||||
"statiSessioneDisponibili": [0, 1, 2, 3],
|
||||
"stato": 0,
|
||||
"statoSessione": 1,
|
||||
"zoneBmask": "3800000000000000",
|
||||
"nome": "AREA 2"
|
||||
},
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-area-2",
|
||||
"visibile": true,
|
||||
"indice": 2,
|
||||
"statiDisponibili": [0, 1, 2, 3, 4],
|
||||
"statiSessioneDisponibili": [0, 1, 2, 3],
|
||||
"stato": 0,
|
||||
"statoSessione": 1,
|
||||
"zoneBmask": "C000000000000000",
|
||||
"nome": "AREA 3"
|
||||
}
|
||||
],
|
||||
"tapparelle": [
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-tapparella-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"stato": "stop",
|
||||
"posizione": 0,
|
||||
"nome": "ESPAN.DOM.01"
|
||||
}
|
||||
],
|
||||
"gruppi": [
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-gruppo-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"nome": "GRUPPOUSC02"
|
||||
}
|
||||
],
|
||||
"scenari": [
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-scenario-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"nome": "SCENARIO02"
|
||||
},
|
||||
{
|
||||
"endpointId": "13762559c53cd093171-scenario-2",
|
||||
"visibile": true,
|
||||
"indice": 2,
|
||||
"nome": "SCENARIO03"
|
||||
}
|
||||
],
|
||||
"datetime": "19:16:44 23/10/2022"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"token": "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoidXNlciIsImNhcGFiaWxpdGllcyI6eyJ6b25lIjoiMTExMTExMTEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMCIsInVzYyI6IjAxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIiwiaW5kaWNlIjowLCJhcmVlIjo3LCJjYW0iOjAsInRhcHAiOjEsImdydXBwaSI6Miwic2NlbmFyaSI6Nn0sImlhdCI6MTY2NjU0NDYzMywiZXhwIjoxNTY2NTQ4MjM0fQ.0N50aK8VrCBvVZuLf2AzLxH96PFES7gql69URKb50cA"
|
||||
}
|
||||
126
home-assistant/tests/components/elmax/fixtures/get_panel.json
Normal file
126
home-assistant/tests/components/elmax/fixtures/get_panel.json
Normal file
@@ -0,0 +1,126 @@
|
||||
{
|
||||
"release": 11.7,
|
||||
"tappFeature": true,
|
||||
"sceneFeature": true,
|
||||
"zone": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-zona-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"nome": "Feed zone 0",
|
||||
"aperta": false,
|
||||
"esclusa": false
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-zona-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"nome": "Feed Zone 1",
|
||||
"aperta": false,
|
||||
"esclusa": false
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-zona-2",
|
||||
"visibile": true,
|
||||
"indice": 2,
|
||||
"nome": "Feed Zone 2",
|
||||
"aperta": false,
|
||||
"esclusa": false
|
||||
}
|
||||
],
|
||||
"uscite": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-uscita-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"nome": "Actuator 0",
|
||||
"aperta": false
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-uscita-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"nome": "Actuator 1",
|
||||
"aperta": false
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-uscita-2",
|
||||
"visibile": true,
|
||||
"indice": 2,
|
||||
"nome": "Actuator 2",
|
||||
"aperta": true
|
||||
}
|
||||
],
|
||||
"aree": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-area-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"nome": "AREA 0",
|
||||
"statiDisponibili": [0, 1, 2, 3, 4],
|
||||
"statiSessioneDisponibili": [0, 1, 2, 3],
|
||||
"stato": 0,
|
||||
"statoSessione": 0
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-area-1",
|
||||
"visibile": true,
|
||||
"indice": 1,
|
||||
"nome": "AREA 1",
|
||||
"statiDisponibili": [0, 1, 2, 3, 4],
|
||||
"statiSessioneDisponibili": [0, 1, 2, 3],
|
||||
"stato": 0,
|
||||
"statoSessione": 0
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-area-2",
|
||||
"visibile": false,
|
||||
"indice": 2,
|
||||
"nome": "AREA 2",
|
||||
"statiDisponibili": [0, 1, 2, 3, 4],
|
||||
"statiSessioneDisponibili": [0, 1, 2, 3],
|
||||
"stato": 0,
|
||||
"statoSessione": 0
|
||||
}
|
||||
],
|
||||
"tapparelle": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-tapparella-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"stato": "stop",
|
||||
"posizione": 100,
|
||||
"nome": "Cover 0"
|
||||
}
|
||||
],
|
||||
"gruppi": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-gruppo-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"nome": "Group 0"
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-gruppo-1",
|
||||
"visibile": false,
|
||||
"indice": 1,
|
||||
"nome": "Group 1"
|
||||
}
|
||||
],
|
||||
"scenari": [
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-scenario-0",
|
||||
"visibile": true,
|
||||
"indice": 0,
|
||||
"nome": "Automation 0"
|
||||
},
|
||||
{
|
||||
"endpointId": "2db3dae30b9102de4d078706f94d0708-scenario-2",
|
||||
"visibile": true,
|
||||
"indice": 2,
|
||||
"nome": "Automation 2"
|
||||
}
|
||||
],
|
||||
"utente": "this.is@test.com",
|
||||
"centrale": "2db3dae30b9102de4d078706f94d0708"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"centrale_online": true,
|
||||
"hash": "2db3dae30b9102de4d078706f94d0708",
|
||||
"username": [{ "name": "this.is@test.com", "label": "Test Panel Name" }]
|
||||
},
|
||||
{
|
||||
"centrale_online": true,
|
||||
"hash": "d8e8fca2dc0f896fd7cb4cb0031ba249",
|
||||
"username": [{ "name": "this.is@test.com", "label": "Test Panel Name" }]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"token": "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiIxYjExYmIxMWJiYjExMTExYjFiMTFiMWIiLCJlbWFpbCI6InRoaXMuaXNAdGVzdC5jb20iLCJyb2xlIjoidXNlciIsImlhdCI6MTYzNjE5OTk5OCwiZXhwIjoxNjM2MjM1OTk4fQ.1C7lXuKyX1HEGOfMxNwxJ2n-CjoW4rwvNRITQxLICv0",
|
||||
"user": {
|
||||
"_id": "1b11bb11bbb11111b1b11b1b",
|
||||
"email": "this.is@test.com",
|
||||
"role": "user"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
# serializer version: 1
|
||||
# name: test_alarm_control_panels[alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_1-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'alarm_control_panel',
|
||||
'entity_category': None,
|
||||
'entity_id': 'alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'AREA 1',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <AlarmControlPanelEntityFeature: 2>,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-area-0',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_alarm_control_panels[alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'changed_by': None,
|
||||
'code_arm_required': False,
|
||||
'code_format': <CodeFormat.NUMBER: 'number'>,
|
||||
'friendly_name': 'Direct Panel https://1.1.1.1:443/api/v2 AREA 1',
|
||||
'supported_features': <AlarmControlPanelEntityFeature: 2>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'disarmed',
|
||||
})
|
||||
# ---
|
||||
# name: test_alarm_control_panels[alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_2-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'alarm_control_panel',
|
||||
'entity_category': None,
|
||||
'entity_id': 'alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_2',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'AREA 2',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <AlarmControlPanelEntityFeature: 2>,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-area-1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_alarm_control_panels[alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_2-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'changed_by': None,
|
||||
'code_arm_required': False,
|
||||
'code_format': <CodeFormat.NUMBER: 'number'>,
|
||||
'friendly_name': 'Direct Panel https://1.1.1.1:443/api/v2 AREA 2',
|
||||
'supported_features': <AlarmControlPanelEntityFeature: 2>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_2',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'disarmed',
|
||||
})
|
||||
# ---
|
||||
# name: test_alarm_control_panels[alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_3-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'alarm_control_panel',
|
||||
'entity_category': None,
|
||||
'entity_id': 'alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_3',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'AREA 3',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <AlarmControlPanelEntityFeature: 2>,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-area-2',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_alarm_control_panels[alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_3-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'changed_by': None,
|
||||
'code_arm_required': False,
|
||||
'code_format': <CodeFormat.NUMBER: 'number'>,
|
||||
'friendly_name': 'Direct Panel https://1.1.1.1:443/api/v2 AREA 3',
|
||||
'supported_features': <AlarmControlPanelEntityFeature: 2>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'alarm_control_panel.direct_panel_https_1_1_1_1_443_api_v2_area_3',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'disarmed',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,377 @@
|
||||
# serializer version: 1
|
||||
# name: test_binary_sensors[binary_sensor.zona_01-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.zona_01',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'ZONA 01',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-zona-0',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_01-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'door',
|
||||
'friendly_name': 'ZONA 01',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.zona_01',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_02e-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.zona_02e',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'ZONA 02e',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-zona-1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_02e-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'door',
|
||||
'friendly_name': 'ZONA 02e',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.zona_02e',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_03a-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.zona_03a',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'ZONA 03a',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-zona-2',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_03a-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'door',
|
||||
'friendly_name': 'ZONA 03a',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.zona_03a',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_04-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.zona_04',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'ZONA 04',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-zona-3',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_04-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'door',
|
||||
'friendly_name': 'ZONA 04',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.zona_04',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_05-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.zona_05',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'ZONA 05',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-zona-4',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_05-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'door',
|
||||
'friendly_name': 'ZONA 05',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.zona_05',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_06-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.zona_06',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'ZONA 06',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-zona-5',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_06-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'door',
|
||||
'friendly_name': 'ZONA 06',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.zona_06',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_07-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.zona_07',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'ZONA 07',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-zona-6',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_07-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'door',
|
||||
'friendly_name': 'ZONA 07',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.zona_07',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_08-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.zona_08',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'ZONA 08',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-zona-7',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.zona_08-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'door',
|
||||
'friendly_name': 'ZONA 08',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.zona_08',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,49 @@
|
||||
# serializer version: 1
|
||||
# name: test_covers[cover.espan_dom_01-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'cover',
|
||||
'entity_category': None,
|
||||
'entity_id': 'cover.espan_dom_01',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'ESPAN.DOM.01',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <CoverEntityFeature: 11>,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-tapparella-0',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_covers[cover.espan_dom_01-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'current_position': 0,
|
||||
'friendly_name': 'ESPAN.DOM.01',
|
||||
'supported_features': <CoverEntityFeature: 11>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'cover.espan_dom_01',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'closed',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,47 @@
|
||||
# serializer version: 1
|
||||
# name: test_switches[switch.uscita_02-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'switch',
|
||||
'entity_category': None,
|
||||
'entity_id': 'switch.uscita_02',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'USCITA 02',
|
||||
'platform': 'elmax',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '13762559c53cd093171-uscita-1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switches[switch.uscita_02-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'USCITA 02',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.uscita_02',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,31 @@
|
||||
"""Tests for the Elmax alarm control panels."""
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.elmax import POLLING_SECONDS
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import init_integration
|
||||
|
||||
from tests.common import snapshot_platform
|
||||
|
||||
WAIT = timedelta(seconds=POLLING_SECONDS)
|
||||
|
||||
|
||||
async def test_alarm_control_panels(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test alarm control panels."""
|
||||
with patch(
|
||||
"homeassistant.components.elmax.ELMAX_PLATFORMS", [Platform.ALARM_CONTROL_PANEL]
|
||||
):
|
||||
entry = await init_integration(hass)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||
27
home-assistant/tests/components/elmax/test_binary_sensor.py
Normal file
27
home-assistant/tests/components/elmax/test_binary_sensor.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""Tests for the Elmax binary sensors."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import init_integration
|
||||
|
||||
from tests.common import snapshot_platform
|
||||
|
||||
|
||||
async def test_binary_sensors(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test binary sensors."""
|
||||
with patch(
|
||||
"homeassistant.components.elmax.ELMAX_PLATFORMS", [Platform.BINARY_SENSOR]
|
||||
):
|
||||
entry = await init_integration(hass)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||
681
home-assistant/tests/components/elmax/test_config_flow.py
Normal file
681
home-assistant/tests/components/elmax/test_config_flow.py
Normal file
@@ -0,0 +1,681 @@
|
||||
"""Tests for the Elmax config flow."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from elmax_api.exceptions import ElmaxBadLoginError, ElmaxBadPinError, ElmaxNetworkError
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components.elmax.const import (
|
||||
CONF_ELMAX_MODE,
|
||||
CONF_ELMAX_MODE_CLOUD,
|
||||
CONF_ELMAX_MODE_DIRECT,
|
||||
CONF_ELMAX_MODE_DIRECT_HOST,
|
||||
CONF_ELMAX_MODE_DIRECT_PORT,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL_CERT,
|
||||
CONF_ELMAX_PANEL_ID,
|
||||
CONF_ELMAX_PANEL_NAME,
|
||||
CONF_ELMAX_PANEL_PIN,
|
||||
CONF_ELMAX_PASSWORD,
|
||||
CONF_ELMAX_USERNAME,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from . import (
|
||||
MOCK_DIRECT_CERT,
|
||||
MOCK_DIRECT_HOST,
|
||||
MOCK_DIRECT_HOST_CHANGED,
|
||||
MOCK_DIRECT_PORT,
|
||||
MOCK_DIRECT_SSL,
|
||||
MOCK_PANEL_ID,
|
||||
MOCK_PANEL_NAME,
|
||||
MOCK_PANEL_PIN,
|
||||
MOCK_PASSWORD,
|
||||
MOCK_USERNAME,
|
||||
MOCK_WRONG_PANEL_PIN,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
MOCK_ZEROCONF_DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=MOCK_DIRECT_HOST,
|
||||
ip_addresses=[MOCK_DIRECT_HOST],
|
||||
hostname="VideoBox.local",
|
||||
name="VideoBox",
|
||||
port=443,
|
||||
properties={
|
||||
"idl": MOCK_PANEL_ID,
|
||||
"idr": MOCK_PANEL_ID,
|
||||
"v1": "PHANTOM64PRO_GSM 11.9.844",
|
||||
"v2": "4.9.13",
|
||||
},
|
||||
type="_elmax-ssl._tcp",
|
||||
)
|
||||
MOCK_ZEROCONF_DISCOVERY_CHANGED_INFO = zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=MOCK_DIRECT_HOST_CHANGED,
|
||||
ip_addresses=[MOCK_DIRECT_HOST_CHANGED],
|
||||
hostname="VideoBox.local",
|
||||
name="VideoBox",
|
||||
port=443,
|
||||
properties={
|
||||
"idl": MOCK_PANEL_ID,
|
||||
"idr": MOCK_PANEL_ID,
|
||||
"v1": "PHANTOM64PRO_GSM 11.9.844",
|
||||
"v2": "4.9.13",
|
||||
},
|
||||
type="_elmax-ssl._tcp",
|
||||
)
|
||||
MOCK_ZEROCONF_DISCOVERY_INFO_NOT_SUPPORTED = zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=MOCK_DIRECT_HOST,
|
||||
ip_addresses=[MOCK_DIRECT_HOST],
|
||||
hostname="VideoBox.local",
|
||||
name="VideoBox",
|
||||
port=443,
|
||||
properties={
|
||||
"idl": MOCK_PANEL_ID,
|
||||
"idr": MOCK_PANEL_ID,
|
||||
"v1": "PHANTOM64PRO_GSM 11.9.844",
|
||||
},
|
||||
type="_elmax-ssl._tcp",
|
||||
)
|
||||
CONF_POLLING = "polling"
|
||||
|
||||
|
||||
async def test_show_menu(hass: HomeAssistant) -> None:
|
||||
"""Test that the form is served with no input."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.MENU
|
||||
assert result["step_id"] == "choose_mode"
|
||||
|
||||
|
||||
async def test_direct_setup(hass: HomeAssistant) -> None:
|
||||
"""Test the standard direct setup case."""
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.components.elmax.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
set_mode_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{"next_step_id": CONF_ELMAX_MODE_DIRECT},
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
set_mode_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_MODE_DIRECT_HOST: MOCK_DIRECT_HOST,
|
||||
CONF_ELMAX_MODE_DIRECT_PORT: MOCK_DIRECT_PORT,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL: MOCK_DIRECT_SSL,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
|
||||
async def test_direct_show_form(hass: HomeAssistant) -> None:
|
||||
"""Test the standard direct show form case."""
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.components.elmax.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
set_mode_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
set_mode_result["flow_id"], {"next_step_id": CONF_ELMAX_MODE_DIRECT}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == CONF_ELMAX_MODE_DIRECT
|
||||
assert result["errors"] is None
|
||||
|
||||
|
||||
async def test_cloud_setup(hass: HomeAssistant) -> None:
|
||||
"""Test the standard cloud setup case."""
|
||||
# Setup once.
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.components.elmax.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
show_form_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{"next_step_id": CONF_ELMAX_MODE_CLOUD},
|
||||
)
|
||||
login_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
},
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
login_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_PANEL_NAME: MOCK_PANEL_NAME,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
|
||||
async def test_zeroconf_form_setup_api_not_supported(hass: HomeAssistant) -> None:
|
||||
"""Test the zeroconf setup case."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data=MOCK_ZEROCONF_DISCOVERY_INFO_NOT_SUPPORTED,
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "not_supported"
|
||||
|
||||
|
||||
async def test_zeroconf_discovery(hass: HomeAssistant) -> None:
|
||||
"""Test discovery of Elmax local api panel."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data=MOCK_ZEROCONF_DISCOVERY_INFO,
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "zeroconf_setup"
|
||||
assert result["errors"] is None
|
||||
|
||||
|
||||
async def test_zeroconf_setup_show_form(hass: HomeAssistant) -> None:
|
||||
"""Test discovery shows a form when activated."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data=MOCK_ZEROCONF_DISCOVERY_INFO,
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "zeroconf_setup"
|
||||
|
||||
|
||||
async def test_zeroconf_setup(hass: HomeAssistant) -> None:
|
||||
"""Test the successful creation of config entry via discovery flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data=MOCK_ZEROCONF_DISCOVERY_INFO,
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL: MOCK_DIRECT_SSL,
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
|
||||
async def test_zeroconf_already_configured(hass: HomeAssistant) -> None:
|
||||
"""Ensure local discovery aborts when same panel is already added to ha."""
|
||||
MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title=f"Elmax Direct ({MOCK_PANEL_ID})",
|
||||
data={
|
||||
CONF_ELMAX_MODE: CONF_ELMAX_MODE_DIRECT,
|
||||
CONF_ELMAX_MODE_DIRECT_HOST: MOCK_DIRECT_HOST,
|
||||
CONF_ELMAX_MODE_DIRECT_PORT: MOCK_DIRECT_PORT,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL: MOCK_DIRECT_SSL,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
CONF_ELMAX_PANEL_ID: MOCK_PANEL_ID,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL_CERT: MOCK_DIRECT_CERT,
|
||||
},
|
||||
unique_id=MOCK_PANEL_ID,
|
||||
).add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data=MOCK_ZEROCONF_DISCOVERY_INFO,
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_zeroconf_panel_changed_ip(hass: HomeAssistant) -> None:
|
||||
"""Ensure local discovery updates the panel data when a the panel changes its IP."""
|
||||
# Simulate an entry already exists for ip MOCK_DIRECT_HOST.
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title=f"Elmax Direct ({MOCK_PANEL_ID})",
|
||||
data={
|
||||
CONF_ELMAX_MODE: CONF_ELMAX_MODE_DIRECT,
|
||||
CONF_ELMAX_MODE_DIRECT_HOST: MOCK_DIRECT_HOST,
|
||||
CONF_ELMAX_MODE_DIRECT_PORT: MOCK_DIRECT_PORT,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL: MOCK_DIRECT_SSL,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
CONF_ELMAX_PANEL_ID: MOCK_PANEL_ID,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL_CERT: MOCK_DIRECT_CERT,
|
||||
},
|
||||
unique_id=MOCK_PANEL_ID,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
# Simulate a MDNS discovery finds the same panel with a different IP (MOCK_ZEROCONF_DISCOVERY_CHANGED_INFO).
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data=MOCK_ZEROCONF_DISCOVERY_CHANGED_INFO,
|
||||
)
|
||||
|
||||
# Expect we abort the configuration as "already configured"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
# Expect the panel ip has been updated.
|
||||
assert (
|
||||
hass.config_entries.async_get_entry(config_entry.entry_id).data[
|
||||
CONF_ELMAX_MODE_DIRECT_HOST
|
||||
]
|
||||
== MOCK_ZEROCONF_DISCOVERY_CHANGED_INFO.host
|
||||
)
|
||||
|
||||
|
||||
async def test_one_config_allowed_cloud(hass: HomeAssistant) -> None:
|
||||
"""Test that only one Elmax configuration is allowed for each panel."""
|
||||
MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_ELMAX_PANEL_ID: MOCK_PANEL_ID,
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
unique_id=MOCK_PANEL_ID,
|
||||
).add_to_hass(hass)
|
||||
|
||||
# Attempt to add another instance of the integration for the very same panel, it must fail.
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
user_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{"next_step_id": CONF_ELMAX_MODE_CLOUD},
|
||||
)
|
||||
login_result = await hass.config_entries.flow.async_configure(
|
||||
user_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
},
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
login_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_PANEL_NAME: MOCK_PANEL_NAME,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_cloud_invalid_credentials(hass: HomeAssistant) -> None:
|
||||
"""Test that invalid credentials throws an error."""
|
||||
with patch(
|
||||
"elmax_api.http.Elmax.login",
|
||||
side_effect=ElmaxBadLoginError(),
|
||||
):
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
show_form_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{"next_step_id": CONF_ELMAX_MODE_CLOUD},
|
||||
)
|
||||
login_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_USERNAME: "wrong_user_name@email.com",
|
||||
CONF_ELMAX_PASSWORD: "incorrect_password",
|
||||
},
|
||||
)
|
||||
assert login_result["step_id"] == CONF_ELMAX_MODE_CLOUD
|
||||
assert login_result["type"] is FlowResultType.FORM
|
||||
assert login_result["errors"] == {"base": "invalid_auth"}
|
||||
|
||||
|
||||
async def test_cloud_connection_error(hass: HomeAssistant) -> None:
|
||||
"""Test other than invalid credentials throws an error."""
|
||||
with patch(
|
||||
"elmax_api.http.Elmax.login",
|
||||
side_effect=ElmaxNetworkError(),
|
||||
):
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
show_form_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{"next_step_id": CONF_ELMAX_MODE_CLOUD},
|
||||
)
|
||||
login_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
},
|
||||
)
|
||||
assert login_result["step_id"] == CONF_ELMAX_MODE_CLOUD
|
||||
assert login_result["type"] is FlowResultType.FORM
|
||||
assert login_result["errors"] == {"base": "network_error"}
|
||||
|
||||
|
||||
async def test_direct_connection_error(hass: HomeAssistant) -> None:
|
||||
"""Test network error while dealing with direct panel APIs."""
|
||||
with patch(
|
||||
"elmax_api.http.ElmaxLocal.login",
|
||||
side_effect=ElmaxNetworkError(),
|
||||
):
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
set_mode_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{"next_step_id": CONF_ELMAX_MODE_DIRECT},
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
set_mode_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_MODE_DIRECT_HOST: MOCK_DIRECT_HOST,
|
||||
CONF_ELMAX_MODE_DIRECT_PORT: MOCK_DIRECT_PORT,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL: MOCK_DIRECT_SSL,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
)
|
||||
assert result["step_id"] == CONF_ELMAX_MODE_DIRECT
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "network_error"}
|
||||
|
||||
|
||||
async def test_direct_wrong_panel_code(hass: HomeAssistant) -> None:
|
||||
"""Test wrong code being specified while dealing with direct panel APIs."""
|
||||
with patch(
|
||||
"elmax_api.http.ElmaxLocal.login",
|
||||
side_effect=ElmaxBadLoginError(),
|
||||
):
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
set_mode_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{"next_step_id": CONF_ELMAX_MODE_DIRECT},
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
set_mode_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_MODE_DIRECT_HOST: MOCK_DIRECT_HOST,
|
||||
CONF_ELMAX_MODE_DIRECT_PORT: MOCK_DIRECT_PORT,
|
||||
CONF_ELMAX_MODE_DIRECT_SSL: MOCK_DIRECT_SSL,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_WRONG_PANEL_PIN,
|
||||
},
|
||||
)
|
||||
assert result["step_id"] == CONF_ELMAX_MODE_DIRECT
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "invalid_auth"}
|
||||
|
||||
|
||||
async def test_unhandled_error(hass: HomeAssistant) -> None:
|
||||
"""Test unhandled exceptions."""
|
||||
with patch(
|
||||
"elmax_api.http.Elmax.get_panel_status",
|
||||
side_effect=Exception(),
|
||||
):
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
show_form_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{"next_step_id": CONF_ELMAX_MODE_CLOUD},
|
||||
)
|
||||
login_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
},
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
login_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_PANEL_NAME: MOCK_PANEL_NAME,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
)
|
||||
assert result["step_id"] == "panels"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "unknown"}
|
||||
|
||||
|
||||
async def test_invalid_pin(hass: HomeAssistant) -> None:
|
||||
"""Test error is thrown when a wrong pin is used to pair a panel."""
|
||||
# Simulate bad pin response.
|
||||
with patch(
|
||||
"elmax_api.http.Elmax.get_panel_status",
|
||||
side_effect=ElmaxBadPinError(),
|
||||
):
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
show_form_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{"next_step_id": CONF_ELMAX_MODE_CLOUD},
|
||||
)
|
||||
login_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
},
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
login_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_PANEL_NAME: MOCK_PANEL_NAME,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
)
|
||||
assert result["step_id"] == "panels"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "invalid_pin"}
|
||||
|
||||
|
||||
async def test_no_online_panel(hass: HomeAssistant) -> None:
|
||||
"""Test no-online panel is available."""
|
||||
# Simulate low-level api returns no panels.
|
||||
with patch(
|
||||
"elmax_api.http.Elmax.list_control_panels",
|
||||
return_value=[],
|
||||
):
|
||||
show_form_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
show_form_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{"next_step_id": CONF_ELMAX_MODE_CLOUD},
|
||||
)
|
||||
login_result = await hass.config_entries.flow.async_configure(
|
||||
show_form_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
},
|
||||
)
|
||||
assert login_result["step_id"] == CONF_ELMAX_MODE_CLOUD
|
||||
assert login_result["type"] is FlowResultType.FORM
|
||||
assert login_result["errors"] == {"base": "no_panel_online"}
|
||||
|
||||
|
||||
async def test_show_reauth(hass: HomeAssistant) -> None:
|
||||
"""Test that the reauth form shows."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_ELMAX_PANEL_ID: MOCK_PANEL_ID,
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
unique_id=MOCK_PANEL_ID,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await entry.start_reauth_flow(hass)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
|
||||
async def test_reauth_flow(hass: HomeAssistant) -> None:
|
||||
"""Test that the reauth flow works."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_ELMAX_PANEL_ID: MOCK_PANEL_ID,
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
unique_id=MOCK_PANEL_ID,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
# Trigger reauth
|
||||
reauth_result = await entry.start_reauth_flow(hass)
|
||||
with patch(
|
||||
"homeassistant.components.elmax.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
reauth_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
},
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
await hass.async_block_till_done()
|
||||
assert result["reason"] == "reauth_successful"
|
||||
|
||||
|
||||
async def test_reauth_panel_disappeared(hass: HomeAssistant) -> None:
|
||||
"""Test that the case where panel is no longer associated with the user."""
|
||||
# Simulate a first setup
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_ELMAX_PANEL_ID: MOCK_PANEL_ID,
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
unique_id=MOCK_PANEL_ID,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
# Trigger reauth
|
||||
reauth_result = await entry.start_reauth_flow(hass)
|
||||
with patch(
|
||||
"elmax_api.http.Elmax.list_control_panels",
|
||||
return_value=[],
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
reauth_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
},
|
||||
)
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "reauth_panel_disappeared"}
|
||||
|
||||
|
||||
async def test_reauth_invalid_pin(hass: HomeAssistant) -> None:
|
||||
"""Test that the case where panel is no longer associated with the user."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_ELMAX_PANEL_ID: MOCK_PANEL_ID,
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
unique_id=MOCK_PANEL_ID,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
# Trigger reauth
|
||||
reauth_result = await entry.start_reauth_flow(hass)
|
||||
with patch(
|
||||
"elmax_api.http.Elmax.get_panel_status",
|
||||
side_effect=ElmaxBadPinError(),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
reauth_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
},
|
||||
)
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "invalid_pin"}
|
||||
|
||||
|
||||
async def test_reauth_bad_login(hass: HomeAssistant) -> None:
|
||||
"""Test bad login attempt at reauth time."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_ELMAX_PANEL_ID: MOCK_PANEL_ID,
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
},
|
||||
unique_id=MOCK_PANEL_ID,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
# Trigger reauth
|
||||
reauth_result = await entry.start_reauth_flow(hass)
|
||||
with patch(
|
||||
"elmax_api.http.Elmax.login",
|
||||
side_effect=ElmaxBadLoginError(),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
reauth_result["flow_id"],
|
||||
{
|
||||
CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN,
|
||||
CONF_ELMAX_USERNAME: MOCK_USERNAME,
|
||||
CONF_ELMAX_PASSWORD: MOCK_PASSWORD,
|
||||
},
|
||||
)
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "invalid_auth"}
|
||||
25
home-assistant/tests/components/elmax/test_cover.py
Normal file
25
home-assistant/tests/components/elmax/test_cover.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""Tests for the Elmax covers."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import init_integration
|
||||
|
||||
from tests.common import snapshot_platform
|
||||
|
||||
|
||||
async def test_covers(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test covers."""
|
||||
with patch("homeassistant.components.elmax.ELMAX_PLATFORMS", [Platform.COVER]):
|
||||
entry = await init_integration(hass)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||
25
home-assistant/tests/components/elmax/test_switch.py
Normal file
25
home-assistant/tests/components/elmax/test_switch.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""Tests for the Elmax switches."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import init_integration
|
||||
|
||||
from tests.common import snapshot_platform
|
||||
|
||||
|
||||
async def test_switches(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test switches."""
|
||||
with patch("homeassistant.components.elmax.ELMAX_PLATFORMS", [Platform.SWITCH]):
|
||||
entry = await init_integration(hass)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||
Reference in New Issue
Block a user