Add tests for KNX diagnostic and expose (#64938)
* Add test for KNX diagnostic * Add test for KNX expose * Apply review suggestions
This commit is contained in:
parent
f49cfe866a
commit
62584b4813
5 changed files with 102 additions and 9 deletions
|
@ -1,5 +1,8 @@
|
|||
"""Test KNX expose."""
|
||||
from homeassistant.components.knx import CONF_KNX_EXPOSE, KNX_ADDRESS
|
||||
import time
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.knx import CONF_KNX_EXPOSE, DOMAIN, KNX_ADDRESS
|
||||
from homeassistant.components.knx.schema import ExposeSchema
|
||||
from homeassistant.const import CONF_ATTRIBUTE, CONF_ENTITY_ID, CONF_TYPE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -123,3 +126,28 @@ async def test_expose_attribute_with_default(hass: HomeAssistant, knx: KNXTestKi
|
|||
# Change state to "off"; no attribute
|
||||
hass.states.async_set(entity_id, "off", {})
|
||||
await knx.assert_write("1/1/8", (0,))
|
||||
|
||||
|
||||
@patch("time.localtime")
|
||||
async def test_expose_with_date(localtime, hass: HomeAssistant, knx: KNXTestKit):
|
||||
"""Test an expose with a date."""
|
||||
localtime.return_value = time.struct_time([2022, 1, 7, 9, 13, 14, 6, 0, 0])
|
||||
await knx.setup_integration(
|
||||
{
|
||||
CONF_KNX_EXPOSE: {
|
||||
CONF_TYPE: "datetime",
|
||||
KNX_ADDRESS: "1/1/8",
|
||||
}
|
||||
},
|
||||
)
|
||||
assert not hass.states.async_all()
|
||||
|
||||
await knx.assert_write("1/1/8", (0x7A, 0x1, 0x7, 0xE9, 0xD, 0xE, 0x20, 0x80))
|
||||
|
||||
await knx.receive_read("1/1/8")
|
||||
await knx.assert_response("1/1/8", (0x7A, 0x1, 0x7, 0xE9, 0xD, 0xE, 0x20, 0x80))
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(entries) == 1
|
||||
|
||||
assert await hass.config_entries.async_unload(entries[0].entry_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue