Hello, this will be a bit chaotic since I’m quite new to Python and Home Assistant Development. (I’m a .NET dev)
I’ve written my first platform integration, it works great (I think)!
It’s configurable only from configuration.yaml
, so no UI flows yet.
Since it’s using an external package to make an API call, the documentation says that I don’t need to test the external functionality, so the only ones that I want to include are initialization tests.
I have 2 working and 2 invalid configurations that I want to test, but I found literally 0 documentation on how to do that. I’ve been trying to understand other people’s code, but I can’t.
Here is what I have so far (GitHub PR):
A setup_platform(..)
method and single class for my entity with an __init__()
and update()
That’s all.
From what I understand, in my tests I should initiate my integration with something like this:
VALID_CONFIG = {
"binary_sensor": {
"platform": "my_platform_domain",
CONF_PERSON_EGN: "0011223344",
CONF_DRIVING_LICENSE: "123456789"
}
}
async def test_valid_config(hass: HomeAssistant) -> None:
initSuccess = await async_setup_component(hass, DOMAIN, VALID_CONFIG)
assert initSuccess
This does not work.
I’ve also tried with a simplifed configuration, without the binary_sensor
level but it still does not work.
Can anyone guide me to what methods to use or which integration I could cannibalize to get my tests to work?
Also I know I should do more checks, and I will, I just can’t get past this stage.
Any help will be greatly appreciated, I’m getting desperate around here.