Device Offline Rule

I have a lot of things in my test script that I need to get into the docs! Instead of using a group and associated Items, you could trigger on Thing change and then iterate through the Items linked to the Thing’s Channels…

from core.rules import rule
from core.triggers import when
from core import osgi
ItemChannelLinkRegistry = osgi.get_service("org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry")

@rule("Reset offline")
@when("Thing kodi:kodi:familyroom changed to OFFLINE")
def device_offline(event):
    for channel in things.get(event.thingUID).channels:
        for item in list(ItemChannelLinkRegistry.getLinkedItemNames(channel.UID)):
            events.postUpdate(item, "UNDEF")
            device_offline.log.warn("item [{}], state [{}]".format(item, items[item]))

I thought that all bindings were to update the state of linked Items to UNDEF when the Thing status changed to OFFLINE. Which bindings are you aware of that do not do this? In testing, I actually found some of my Kodi Items are not marked as UNDEF…

2019-08-29 20:32:45.635 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Volume], state [100]
2019-08-29 20:32:45.636 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Mute], state [OFF]
2019-08-29 20:32:45.637 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Control], state [PAUSE]
2019-08-29 20:32:45.638 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Stop], state [ON]
2019-08-29 20:32:45.639 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Playuri], state [UNDEF]
2019-08-29 20:32:45.640 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Pvropentv], state [UNDEF]
2019-08-29 20:32:45.641 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Pvropenradio], state [UNDEF]
2019-08-29 20:32:45.642 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Pvrchannel], state [UNDEF]
2019-08-29 20:32:45.643 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Notification], state [UNDEF]
2019-08-29 20:32:45.644 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Input], state [UNDEF]
2019-08-29 20:32:45.645 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Inputtext], state [UNDEF]
2019-08-29 20:32:45.646 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Inputaction], state [UNDEF]
2019-08-29 20:32:45.647 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Systemcommand], state [UNDEF]
2019-08-29 20:32:45.648 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Title], state [UNDEF]
2019-08-29 20:32:45.649 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Showtitle], state [UNDEF]
2019-08-29 20:32:45.650 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Album], state [UNDEF]
2019-08-29 20:32:45.651 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Artist], state [UNDEF]
2019-08-29 20:32:45.652 [WARN ] [jsr223.jython.Update status of Items linked to Channels of OFFLINE Thing] - item [DS_FamilyRoom_Kodi_Mediatype], state [UNDEF]

@cweitkamp, am I correct in my assumption that all Items linked to a Channel of an OFFLINE Thing should be marked as UNDEF?