id: refreshstate-subscriber topic: events title: RefreshStateSubscriber — the HC3 event feed, simulated by flua pins: - tests/test_recipes.py::test_motion_lights_reacts_to_the_breach_event verified: flua 0.1.168


RefreshStateSubscriber — the HC3 event feed, simulated by flua

The mechanism for reactive QAs (motion → light instantly, not on a poll) — the HC3's refreshStates feed, which flua simulates offline:

local events = RefreshStateSubscriber()
events:subscribe(
  function(event)                          -- predicate: which events
    return event.type == "DevicePropertyUpdatedEvent"
      and event.data and event.data.id == MOTION
      and event.data.property == "value"
  end,
  function(event) self:checkMotion() end)  -- handler
events:run()