gluap / pyduofern-hacs

Repository managing hacs-integration for pyduofern
MIT License
27 stars 8 forks source link

Set running time #47

Open Rumsgurke opened 9 months ago

Rumsgurke commented 9 months ago

First of all, thank you very much. The integration works like a charm. With some actors like Rademacher DuoFern 9471-1 you can't set the maximum and minimum positions manually. That value must be set via the interface as running time in seconds. Such an actor isn't working properly without that value. Therefore I've copied one of your services locally and made some adjustments:

def set_running_time(call: ServiceCall) -> None:
    device_id = None
    hass_device_id = call.data.get('device_id', None)
    time = call.data.get('time', None)

    def get_device_id(hass_entity_id):
        for ent in hass.data[DOMAIN]['devices'].values():
            if ent.entity_id == hass_entity_id:
                return ent._duofernId
        return None

    device_ids = [get_device_id(i) for i in hass_device_id]
    _LOGGER.info(f"Updating these devices {' '.join(device_ids)}")
    if not device_ids:
        _LOGGER.warning("Found no valid device ids???")
    for device_id in device_ids:
        if device_id is not None:
            if device_id not in hass.data[DOMAIN]['stick'].duofern_parser.modules['by_code']:
                _LOGGER.warning(
                    f"{device_id} is not a valid duofern device, I only know {hass.data[DOMAIN]['stick'].duofern_parser.modules['by_code'].keys()}. Gonna handle the other devices in {device_ids} though.")
                continue
            _LOGGER.info(f"update runningTime on {device_id} with time {time}")
            getDuofernStick(hass).command(device_id,"runningTime",time)

The result can be controlled by the services dump_device_state. I liked the idea to do it as a service. You may want to add a service like that to a future release.

Best regards.