Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

[Add Binary Sensor] - duplicate init #1

@ChristophCaina

Description

@ChristophCaina

Logger:

2024-07-17 11:45:57.662 INFO (MainThread) [homeassistant.components.sensor] Setting up oilfox.sensor
2024-07-17 11:45:57.662 INFO (MainThread) [custom_components.oilfox.sensor] OilFox: Setup User: [email protected]
2024-07-17 11:45:57.662 INFO (MainThread) [custom_components.oilfox.sensor] Load custom timeout value: 240
2024-07-17 11:45:57.663 INFO (MainThread) [custom_components.oilfox.sensor] Load default poll intervall: 30
2024-07-17 11:45:57.663 INFO (MainThread) [custom_components.oilfox.sensor] OilFox: Found Device in API: OF7090002028
2024-07-17 11:45:57.663 INFO (MainThread) [custom_components.oilfox.sensor] OilFox: Found Device in API: OF7090001854
2024-07-17 11:45:57.673 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up oilfox.binary_sensor
2024-07-17 11:45:57.673 INFO (MainThread) [custom_components.oilfox.binary_sensor] OilFox: Setup User: [email protected]
2024-07-17 11:45:57.673 INFO (MainThread) [custom_components.oilfox.binary_sensor] Load custom timeout value: 240
2024-07-17 11:45:57.673 INFO (MainThread) [custom_components.oilfox.binary_sensor] Load default poll intervall: 30
2024-07-17 11:45:57.674 INFO (MainThread) [custom_components.oilfox.binary_sensor] OilFox: Found Device in API: OF7090002028
2024-07-17 11:45:57.674 INFO (MainThread) [custom_components.oilfox.binary_sensor] OilFox: Found Device in API: OF7090001854

caused by in sensor.py and binary_sensor.py

async def async_setup_entry(
    hass: HomeAssistant,
    config_entry: ConfigEntry,
    async_add_entities: AddEntitiesCallback,
) -> None:
    """Initialize OilFox Integration config entry."""

    _LOGGER.info("OilFox: Setup User: %s", config_entry.data[CONF_EMAIL])
    email = config_entry.data[CONF_EMAIL]
    password = config_entry.data[CONF_PASSWORD]

    if CONF_HTTP_TIMEOUT in config_entry.options:
        timeout = config_entry.options[CONF_HTTP_TIMEOUT]
        _LOGGER.info(
            "Load custom timeout value: %s", config_entry.options[CONF_HTTP_TIMEOUT]
        )
    else:
        timeout = TIMEOUT
        _LOGGER.info("Load default timeout value: %s", timeout)

    if CONF_POLL_INTERVAL in config_entry.options:
        poll_interval = config_entry.options[CONF_POLL_INTERVAL]
        _LOGGER.info(
            "Load custom poll interval: %s", config_entry.options[CONF_POLL_INTERVAL]
        )
    else:
        poll_interval = POLL_INTERVAL
        _LOGGER.info("Load default poll intervall: %s", poll_interval)

    coordinator = hass.data[DOMAIN][config_entry.entry_id]
    coordinator.update_interval = timedelta(minutes=poll_interval)
    _LOGGER.debug("OilFox Coordinator Data Result: %s", repr(coordinator.data))
    if coordinator.data is None or coordinator.data is False:
        raise ConfigEntryNotReady(
            "Error on Coordinator Data Result: " + repr(coordinator.data)
        )
    oilfox_devices = coordinator.data["items"]
    entities = []
    for oilfox_device in oilfox_devices:
        _LOGGER.info("OilFox: Found Device in API: %s", oilfox_device["hwid"])
        for binary_sensor in BINARY_SENSORS.items():
            _LOGGER.debug(
                "OilFox: Create Binary-Sensor %s for Device %s",
                binary_sensor[0],
                oilfox_device["hwid"],
            )
            oilfox_binary_sensor = OilFoxBinarySensor(
                coordinator,
                OilFox(
                    email,
                    password,
                    oilfox_device["hwid"],
                    timeout=timeout,
                    poll_interval=poll_interval,
                ),
                binary_sensor[1],
                hass,
            )
            oilfox_binary_sensor.set_api_response(oilfox_device)
            if binary_sensor[0] == "validationErrorStatus":
                if "validationError" in oilfox_device:
                    _LOGGER.debug(
                        "Prefill entity %s with %s",
                        binary_sensor[0],
                        "True",
                    )
                    oilfox_binary_sensor.set_state(True)

Can this be moved to init.py ?

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions