mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 10:47:51 +00:00

* knx entity CRUD - initial commit - switch * platform dependent schema * coerce empty GA-lists to None * read entity configuration from WS * use entity_id instead of unique_id for lookup * Add device support * Rename KNXEntityStore to KNXConfigStore * fix test after rename * Send schema options for creating / editing entities * Return entity_id after entity creation * remove device_class config in favour of more-info-dialog settings * refactor group address schema for custom selector * Rename GA keys and remove invalid keys from schema * fix rebase * Fix deleting devices and their entities * Validate entity schema in extra step - return validation infos * Use exception to signal validation error; return validated data * Forward validation result when editing entities * Get proper validation error message for optional GAs * Add entity validation only WS command * use ulid instead of uuid * Fix error handling for edit unknown entity * Remove unused optional group address sets from validated schema * Add optional dpt field for ga_schema * Move knx config things to sub-key * Add light platform * async_forward_entry_setups only once * Test crate and remove devices * Test removing entities of a removed device * Test entity creation and storage * Test deleting entities * Test unsuccessful entity creation * Test updating entity data * Test get entity config * Test validate entity * Update entity data by entity_id instead of unique_id * Remove unnecessary uid unique check * remove schema_options * test fixture for entity creation * clean up group address schema class can be used to add custom serializer later * Revert: Add light platfrom * remove unused optional_ga_schema * Test GASelector * lint tests * Review * group entities before adding * fix / ignore mypy * always has_entity_name * Entity name: check for empty string when no device * use constants instead of strings in schema * Fix mypy errors for voluptuous schemas --------- Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
3.3 KiB
3.3 KiB
Testing the KNX integration
A KNXTestKit instance can be requested from a fixture. It provides convenience methods
to test outgoing KNX telegrams and inject incoming telegrams.
To test something add a test function requesting the hass
and knx
fixture and
set up the KNX integration by passing a KNX config dict to knx.setup_integration
.
async def test_something(hass, knx):
await knx.setup_integration({
"switch": {
"name": "test_switch",
"address": "1/2/3",
}
}
)
Asserting outgoing telegrams
All outgoing telegrams are pushed to an assertion queue. Assert them in order they were sent.
knx.assert_no_telegram
Asserts that no telegram was sent (assertion queue is empty).knx.assert_telegram_count(count: int)
Asserts thatcount
telegrams were sent.knx.assert_read(group_address: str, response: int | tuple[int, ...] | None = None)
Asserts that a GroupValueRead telegram was sent togroup_address
. The telegram will be removed from the assertion queue. Optionally inject incoming GroupValueResponse telegram after reception to clear the value reader waiting task. This can also be done manually withknx.receive_response
.knx.assert_response(group_address: str, payload: int | tuple[int, ...])
Asserts that a GroupValueResponse telegram withpayload
was sent togroup_address
. The telegram will be removed from the assertion queue.knx.assert_write(group_address: str, payload: int | tuple[int, ...])
Asserts that a GroupValueWrite telegram withpayload
was sent togroup_address
. The telegram will be removed from the assertion queue.
Change some states or call some services and assert outgoing telegrams.
# turn on switch
await hass.services.async_call(
"switch", "turn_on", {"entity_id": "switch.test_switch"}, blocking=True
)
# assert ON telegram
await knx.assert_write("1/2/3", True)
Injecting incoming telegrams
knx.receive_read(group_address: str)
Inject and process a GroupValueRead telegram addressed togroup_address
.knx.receive_response(group_address: str, payload: int | tuple[int, ...])
Inject and process a GroupValueResponse telegram addressed togroup_address
containingpayload
.knx.receive_write(group_address: str, payload: int | tuple[int, ...])
Inject and process a GroupValueWrite telegram addressed togroup_address
containingpayload
.
Receive some telegrams and assert state.
# receive OFF telegram
await knx.receive_write("1/2/3", False)
# assert OFF state
state = hass.states.get("switch.test_switch")
assert state.state is STATE_OFF
Notes
- For
payload
inassert_*
andreceive_*
useint
for DPT 1, 2 and 3 payload values (DPTBinary) andtuple
for other DPTs (DPTArray). await self.hass.async_block_till_done()
is called beforeKNXTestKit.assert_*
and afterKNXTestKit.receive_*
so you don't have to explicitly call it.- Make sure to assert every outgoing telegram that was created in a test.
assert_no_telegram
is automatically called on teardown. - Make sure to
knx.receive_response()
for every Read-request sent form StateUpdater, or to pass its timeout, to not have lingering tasks when finishing the tests.