Hi,
Relatively new to python/custom_integration. The overall custom integration works well, it basically creates multiple sensors from an iot device by polling the sensors. I do have the serial number, Mac address and name of the device from polling as well.
The configuration happens in YAML, so no config_flow:
sensor:
- platform: myiot
name: "My IOT Device"
host: 192.168.0.46
scan_interval: 60
username: admin
password: password
Here is some of the relevant code from the sensor.py file:
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
api = IOTApi(config.get(CONF_USERNAME), config.get(CONF_PASSWORD), config.get(CONF_HOST))
async def async_update_data():
async with async_timeout.timeout(DEFAULT_TIMEOUT):
try:
...............
)
await coordinator.async_refresh()
await update_unique_ids(hass, coordinator.data)
device_registry = async_get_device_registry(hass)
device_registry.async_get_or_create(
config_entry_id=None,
identifiers={(DOMAIN, 'A840411679E7__00_0010_2211_10_0100__000_2_0')},
manufacturer="My Manufacturer",
model="My Model",
name="My Device Name",
via_device=None,
entry_type="device",
connections=[(CONNECTION_NETWORK_MAC, "A840411679E7")],
)
async_add_entities(
MyIOTSensor(coordinator, unique_id, endpoint) for unique_id, endpoint in coordinator.data.items()
)
Since I am using a Platform approach (async_setup_platform), the config_entry.entry_id (which is hass.config_entries.async_get_entry(DOMAIN).entry_id) is not available, and I have set config_entry_id=None. However, Home Assistant does not like that.
I really struggle here, have read the documentation so many times that I don’t know where my head is.
My questions are:
-
Can I use devices for a custom_integration that is setup without config_flow.py?
-
If yes, what am I doing wrong, since - after hours of logging - I have come to the conclusion although that the integration uses the platform and reads the config from configuration.yaml, there are no config_entries available.
-
If no, then I have to go the UI route which means way more complex programming since every device would then have to be setup via config_flow and UI, unless there is a trick/better way almost like a dummy config_flow/UI to trigger the setup of devices?
Thanks for any advice.
M