List items rendered with an oh-repeater are not updated by state changes

I’ve designed a custom widget listing members of a group in a oh-card-list and rendering them as oh-list-item elements with icon, label and a badge. To render the list elements I us an oh-repeater:

uid: person_present_state_widget
tags:
  - list
  - presence
props:
  parameters:
    - label: Title
      name: title
      required: true
      type: TEXT
    - context: item
      description: The group holding presence state items
      label: Item
      name: item
      required: true
      type: TEXT
  parameterGroups: []
timestamp: Jan 12, 2022, 12:22:00 PM
component: oh-list-card
config:
  title: =props.title
slots:
  default:
    - component: oh-list
      config:
        mediaList: true
      slots:
        default:
          - component: oh-repeater
            config:
              for: item
              sourceType: itemsInGroup
              groupItem: =props.item
            slots:
              default:
                - component: oh-list-item
                  config:
                    title: =loop.item.label
                    icon: f7:person_circle
                    iconColor: '=loop.item.state == "ON" ? "green" : "red"'
                    badgeColor: '=loop.item.state == "ON" ? "green" : "red"'
                    badge: '=loop.item.state == "ON" ? "Anwesend" : "Abwesend"'

The design was inspired by the wonderful article “A couple of simple oh-repeater examples” done by Rich.

The only thing that bothers me is, that the list item elements rendered by the oh-repeater do not get updated on state changes. They are, so to speak, “disconnected”. Only when I do a refresh (F5) on the browser, state changes get reflected due to new rendering.

Is this the expected behavior or simply a bug in the oh-repeater?

Platform information:

  • Hardware: Intel Core i3-4130T/x64/16GiB RAM
  • OS: Docker on Ubuntu 20.04 LTS
  • Java Runtime Environment: OpenJDK 64-Bit Server VM 11.0.13
  • openHAB version: 3.2.0
1 Like

If you get item state with items[loop.item.name].state then your items with refresh. loop.item.state is just getting the state that was returned by the repeater’s api call and that’s not changing because the api is not being called again (how would the widget know when to make another api call?). The items object, on the other hand, maintains the up to date item state.

4 Likes

Thanks Justin,

that did the trick. I didn’t know that.