Ensure zone in update payload for konnected (#34289)
This commit is contained in:
parent
0d999649c0
commit
e20bfdd19c
2 changed files with 150 additions and 1 deletions
|
@ -348,6 +348,7 @@ class KonnectedView(HomeAssistantView):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
zone_num = str(payload.get(CONF_ZONE) or PIN_TO_ZONE[payload[CONF_PIN]])
|
zone_num = str(payload.get(CONF_ZONE) or PIN_TO_ZONE[payload[CONF_PIN]])
|
||||||
|
payload[CONF_ZONE] = zone_num
|
||||||
zone_data = device[CONF_BINARY_SENSORS].get(zone_num) or next(
|
zone_data = device[CONF_BINARY_SENSORS].get(zone_num) or next(
|
||||||
(s for s in device[CONF_SENSORS] if s[CONF_ZONE] == zone_num), None
|
(s for s in device[CONF_SENSORS] if s[CONF_ZONE] == zone_num), None
|
||||||
)
|
)
|
||||||
|
|
|
@ -561,7 +561,7 @@ async def test_api(hass, aiohttp_client, mock_panel):
|
||||||
assert result == {"message": "ok"}
|
assert result == {"message": "ok"}
|
||||||
|
|
||||||
|
|
||||||
async def test_state_updates(hass, aiohttp_client, mock_panel):
|
async def test_state_updates_zone(hass, aiohttp_client, mock_panel):
|
||||||
"""Test callback view."""
|
"""Test callback view."""
|
||||||
await async_setup_component(hass, "http", {"http": {}})
|
await async_setup_component(hass, "http", {"http": {}})
|
||||||
|
|
||||||
|
@ -707,3 +707,151 @@ async def test_state_updates(hass, aiohttp_client, mock_panel):
|
||||||
assert result == {"message": "ok"}
|
assert result == {"message": "ok"}
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get("sensor.temper_temperature").state == "42.0"
|
assert hass.states.get("sensor.temper_temperature").state == "42.0"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_state_updates_pin(hass, aiohttp_client, mock_panel):
|
||||||
|
"""Test callback view."""
|
||||||
|
await async_setup_component(hass, "http", {"http": {}})
|
||||||
|
|
||||||
|
device_config = config_flow.CONFIG_ENTRY_SCHEMA(
|
||||||
|
{
|
||||||
|
"host": "1.2.3.4",
|
||||||
|
"port": 1234,
|
||||||
|
"id": "112233445566",
|
||||||
|
"model": "Konnected",
|
||||||
|
"access_token": "abcdefgh",
|
||||||
|
"default_options": config_flow.OPTIONS_SCHEMA({config_flow.CONF_IO: {}}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
device_options = config_flow.OPTIONS_SCHEMA(
|
||||||
|
{
|
||||||
|
"io": {
|
||||||
|
"1": "Binary Sensor",
|
||||||
|
"2": "Binary Sensor",
|
||||||
|
"3": "Binary Sensor",
|
||||||
|
"4": "Digital Sensor",
|
||||||
|
"5": "Digital Sensor",
|
||||||
|
"6": "Switchable Output",
|
||||||
|
"out": "Switchable Output",
|
||||||
|
},
|
||||||
|
"binary_sensors": [
|
||||||
|
{"zone": "1", "type": "door"},
|
||||||
|
{"zone": "2", "type": "window", "name": "winder", "inverse": True},
|
||||||
|
{"zone": "3", "type": "door"},
|
||||||
|
],
|
||||||
|
"sensors": [
|
||||||
|
{"zone": "4", "type": "dht"},
|
||||||
|
{"zone": "5", "type": "ds18b20", "name": "temper"},
|
||||||
|
],
|
||||||
|
"switches": [
|
||||||
|
{
|
||||||
|
"zone": "out",
|
||||||
|
"name": "switcher",
|
||||||
|
"activation": "low",
|
||||||
|
"momentary": 50,
|
||||||
|
"pause": 100,
|
||||||
|
"repeat": 4,
|
||||||
|
},
|
||||||
|
{"zone": "6"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain="konnected",
|
||||||
|
title="Konnected Alarm Panel",
|
||||||
|
data=device_config,
|
||||||
|
options=device_options,
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
# Add empty data field to ensure we process it correctly (possible if entry is ignored)
|
||||||
|
entry = MockConfigEntry(domain="konnected", title="Konnected Alarm Panel", data={},)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
await async_setup_component(
|
||||||
|
hass,
|
||||||
|
konnected.DOMAIN,
|
||||||
|
{konnected.DOMAIN: {konnected.CONF_ACCESS_TOKEN: "1122334455"}},
|
||||||
|
)
|
||||||
|
is True
|
||||||
|
)
|
||||||
|
|
||||||
|
client = await aiohttp_client(hass.http.app)
|
||||||
|
|
||||||
|
# Test updating a binary sensor
|
||||||
|
resp = await client.post(
|
||||||
|
"/api/konnected/device/112233445566",
|
||||||
|
headers={"Authorization": "Bearer abcdefgh"},
|
||||||
|
json={"pin": "1", "state": 0},
|
||||||
|
)
|
||||||
|
assert resp.status == 200
|
||||||
|
result = await resp.json()
|
||||||
|
assert result == {"message": "ok"}
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert hass.states.get("binary_sensor.konnected_445566_zone_1").state == "off"
|
||||||
|
|
||||||
|
resp = await client.post(
|
||||||
|
"/api/konnected/device/112233445566",
|
||||||
|
headers={"Authorization": "Bearer abcdefgh"},
|
||||||
|
json={"pin": "1", "state": 1},
|
||||||
|
)
|
||||||
|
assert resp.status == 200
|
||||||
|
result = await resp.json()
|
||||||
|
assert result == {"message": "ok"}
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert hass.states.get("binary_sensor.konnected_445566_zone_1").state == "on"
|
||||||
|
|
||||||
|
# Test updating sht sensor
|
||||||
|
resp = await client.post(
|
||||||
|
"/api/konnected/device/112233445566",
|
||||||
|
headers={"Authorization": "Bearer abcdefgh"},
|
||||||
|
json={"pin": "6", "temp": 22, "humi": 20},
|
||||||
|
)
|
||||||
|
assert resp.status == 200
|
||||||
|
result = await resp.json()
|
||||||
|
assert result == {"message": "ok"}
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert hass.states.get("sensor.konnected_445566_sensor_4_humidity").state == "20"
|
||||||
|
assert (
|
||||||
|
hass.states.get("sensor.konnected_445566_sensor_4_temperature").state == "22.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
resp = await client.post(
|
||||||
|
"/api/konnected/device/112233445566",
|
||||||
|
headers={"Authorization": "Bearer abcdefgh"},
|
||||||
|
json={"pin": "6", "temp": 25, "humi": 23},
|
||||||
|
)
|
||||||
|
assert resp.status == 200
|
||||||
|
result = await resp.json()
|
||||||
|
assert result == {"message": "ok"}
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert hass.states.get("sensor.konnected_445566_sensor_4_humidity").state == "23"
|
||||||
|
assert (
|
||||||
|
hass.states.get("sensor.konnected_445566_sensor_4_temperature").state == "25.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test updating ds sensor
|
||||||
|
resp = await client.post(
|
||||||
|
"/api/konnected/device/112233445566",
|
||||||
|
headers={"Authorization": "Bearer abcdefgh"},
|
||||||
|
json={"pin": "7", "temp": 32, "addr": 1},
|
||||||
|
)
|
||||||
|
assert resp.status == 200
|
||||||
|
result = await resp.json()
|
||||||
|
assert result == {"message": "ok"}
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert hass.states.get("sensor.temper_temperature").state == "32.0"
|
||||||
|
|
||||||
|
resp = await client.post(
|
||||||
|
"/api/konnected/device/112233445566",
|
||||||
|
headers={"Authorization": "Bearer abcdefgh"},
|
||||||
|
json={"pin": "7", "temp": 42, "addr": 1},
|
||||||
|
)
|
||||||
|
assert resp.status == 200
|
||||||
|
result = await resp.json()
|
||||||
|
assert result == {"message": "ok"}
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert hass.states.get("sensor.temper_temperature").state == "42.0"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue