groups

Rule languages supports groups

    • Given Clean OpenHAB with latest Ruby Libraries
    • And groups:
      namegroup
      House
      GroundFloorHouse
      LivingroomGroundFloor
      SensorsHouse
      TemperaturesSensors
    • And items:
      typenamelabelstategroups
      NumberLivingroom_TempLiving Room temperature70Livingroom, Temperatures
      NumberBedroom_TempBedroom temperature50GroundFloor, Temperatures
      NumberDen_TempDen temperature30GroundFloor, Temperatures
  • Ability to operate on the items in a group using enumerable methods

    • Given code in a rules file
      logger.info("Total Temperatures: #{Temperatures.count}")
      logger.info("Temperatures: #{House.all_members.sort_by(&:label).map(&:label).join(', ')}")
    • When I deploy the rules file
    • Then It should log 'Total Temperatures: 3' within 5 seconds
    • And It should log 'Temperatures: Bedroom temperature, Den temperature, Living Room temperature' within 5 seconds
  • Access to group data

    • Given code in a rules file
      logger.info("Group: #{Temperatures.name}")
    • When I deploy the rules file
    • Then It should log 'Group: Temperatures' within 5 seconds
  • Ability to operate on the items in nested group using all_members and enumerable methods

    • Given code in a rules file
      logger.info("House Count: #{House.all_members.count}")
      logger.info("Items: #{House.all_members.sort_by(&:label).map(&:label).join(', ')}")
    • When I deploy the rules file
    • Then It should log 'House Count: 3' within 5 seconds
    • And It should log 'Items: Bedroom temperature, Den temperature, Living Room temperature' within 5 seconds
  • Access to sub groups using all_members(:groups)

    • Given code in a rules file
      logger.info("House Sub Groups: #{House.all_members(:groups).count}")
      logger.info("Groups: #{House.all_members(:groups).sort_by(&:id).map(&:id).join(', ')}")
    • When I deploy the rules file
    • Then It should log 'House Sub Groups: 4' within 5 seconds
    • And It should log 'Groups: GroundFloor, Livingroom, Sensors, Temperatures' within 5 seconds
  • Access to parent groups using groups method

    • Given code in a rules file
      logger.info("Parent Groups: #{Temperatures.groups.map(&:id).sort.join(', ')}")
    • When I deploy the rules file
    • Then It should log 'Parent Groups: Sensors' within 5 seconds
  • Filter output of all_members with a block

    • Given code in a rules file
      logger.info(House.all_members { |item| /.*room.*/.match?(item.name) }.sort_by(&:name).map(&:name).join(', '))
    • When I deploy the rules file
    • Then It should log ' Bedroom_Temp, Livingroom, Livingroom_Temp' within 5 seconds
  • Fetch Group by name

    • And code in a rules file
      logger.info("Sensors Group: #{groups['Sensors'].name}")
    • When I deploy the rules file
    • Then It should log 'Sensors Group: Sensors' within 5 seconds
  • Groups have enumerable based math functions

    • Given code in a rules file
      logger.info("Max is #{Temperatures.max}")
      logger.info("Min is #{Temperatures.min}")
    • When I deploy the rules file
    • Then It should log "Max is 70" within 5 seconds
    • And It should log "Min is 30" within 5 seconds
  • Group update trigger has event.item in run block

    • Given code in a rules file
      rule 'group member updated' do
        updated Temperatures.members
        run do |event|
          logger.info("event.item is #{event.item.name}")
        end
      end
      
      rule 'update a group member' do
        on_start
        run { Livingroom_Temp.update 65 }
      end
    • When I deploy the rules file
    • Then It should log 'event.item is Livingroom_Temp' within 5 seconds
  • Commands sent to a group are propagated to the group items

    • Given code in a rules file
        GroundFloor.<method> <value>
    • When I deploy the rules file
    • Then "Bedroom_Temp" should be in state "<value>" within 5 seconds
    • And "Den_Temp" should be in state "<value>" within 5 seconds

    Examples:

    method value
    << 55
    command 60
  • Groups work in case statements

    • Given groups:
      nametypefunctionparams
      SwitchesSwitchANDON, OFF
      ContactsContactOROPEN, CLOSED
      ShuttersRollershutterANDUP, DOWN
    • And items:
      typenamelabelstategroups
      SwitchSwitchOneSwitch OneONSwitches
      SwitchSwitchTwoSwitch TwoOFFSwitches
      ContactContactOneContact OneOPENContacts
      ContactContactTwoContact TwoCLOSEDContacts
      RollershutterShutterOneShutter One0Shutters
      RollershutterShutterTwoShutter Two50Shutters
    • And code in a rules file
      case Contacts
      when OPEN then logger.info('At least one contact is OPEN')
      when CLOSED then logger.info('All contacts are CLOSED')
      end
      
      case Switches
      when ON then logger.info('All switches are ON')
      when OFF then logger.info('At least one switch is OFF')
      end
      
      case Shutters
      when 0 then logger.info('All shutters are UP')
      when 100 then logger.info('At least one shutter is not UP')
      end
    • When I deploy the rules file
    • Then It should log "At least one contact is OPEN" within 5 seconds
    • And It should log "At least one switch is OFF" within 5 seconds
    • And It should log "At least one shutter is not UP" within 5 seconds
  • members on groups indicates to rules engine to trigger on changes to any members of the group

    • Given a deployed rule:
      rule 'group member updated' do
        updated Temperatures.members
        run do |event|
          logger.info("Group temperature updated")
        end
      end
    • When update state for item "Livingroom_Temp" to "65"
    • Then It should log 'Group temperature updated' within 5 seconds
  • Can iterate group members

    • Given code in a rules file:
      logger.info("Ground Floor: #{GroundFloor.members.sort_by(&:name).map(&:name).join(', ')}")
    • When I deploy the rules file
    • Then It should log 'Ground Floor: Bedroom_Temp, Den_Temp, Livingroom' within 5 seconds
  • Changes to groups is visible to running rules

    • Given code in a rules file:
      rule 'test' do
        on_start
        run { logger.info(Temperatures.sort_by(&:name).map(&:name).join(', ')) }
        delay 10.seconds
        run { logger.info(Temperatures.sort_by(&:name).map(&:name).join(', ')) }
      end
    • When I deploy the rules file
    • Then It should log "Bedroom_Temp, Den_Temp, Livingroom_Temp" within 5 seconds
    • But if I wait 5 seconds
    • And I add items:
      typenamelabelstategroups
      NumberLivingroom_TempLiving Room temperature70
      NumberKitchen_TempKitchen temperature60Temperatures
    • Then It should log "Bedroom_Temp, Den_Temp, Kitchen_Temp" within 10 seconds
  • Changing of Group type updates methods

    • Given groups:
      nametype
      SwitchesSwitch
    • And code in a rules file:
      rule 'test' do
        on_start
        run { logger.info(Switches.respond_to?(:on?)) }
        delay 10.seconds
        run { logger.info(Switches.respond_to?(:on?)) }
      end
    • When I deploy the rules file
    • Then It should log "true" within 5 seconds
    • But if I wait 5 seconds
    • And groups:
      nametype
      SwitchesContact
    • Then It should log "false" within 10 seconds
  • Can add lazy arrays together

    • Given code in a rules file
      logger.info("Item+Group Count: #{(items + groups).count}")
    • When I deploy the rules file
    • Then It should log 'Item+Group Count: 13' within 5 seconds