HABApp: Problem retrigger a countdown timer

In OH4.3 i had some HABApp rules using countdown timers. Currently I’m migrating my rules to OH5.0 and HABApp 25.07.0. Those rules using Contdown timers won’t work anymore, they throw an exception, when I try to retrigger the countdown:

AttributeError: 'CountdownJobControl' object has no attribute 'countdown'. Did you mean: 'set_countdown'? 

Here is a small rule to demonstrate:

#!/usr/bin/env python
# -*- coding: ISO-8859-1 -*-

import logging
import HABApp
from HABApp.core.items import Item
from HABApp.core.events import ValueUpdateEvent, ValueUpdateEventFilter

Log = logging.getLogger('MyRule')

class MyCountdownRule(HABApp.Rule):
    def __init__(self):
        super().__init__()
        self._Light = 1
        self._TimerHandle = self.run.countdown(2, self._SwitchRockerOff)
        self._TimerHandle.reset()
        Log.debug('Timer: {}'.format('started'))

    def _SwitchRockerOff(self):
        Log.debug('Timer: {}'.format('triggered'))
        if self._Light:
            Log.debug('Timer: {}'.format('re-triggered'))
            self._TimerHandle.countdown(2)               # <-- throws exception
            self._TimerHandle.reset()
            self._Light = 0
        else:
            Log.debug('Timer: {}'.format('triggered0'))
            self._Light = 0

MyCountdownRule = MyCountdownRule()

So my question is, how to use countdown timer correctly in HABApp 25+ especially, how to retrigger it?

After a bit of research :blush: , I found following solution:

Instead using this:

self._TimerHandle.countdown(2)

I can use this:

self._TimerHandle.set_countdown(2)

This works like expected. BTW: The error message suggested this solution already, but I did’t believe it :rofl:

I really love HABApp!

I guess you migrated from the old to the new scheduler.
It has gotten much more powerful, check out the docs and the examples

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.