Announcement

Collapse
No announcement yet.

Deleted devices remaining in categories

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Deleted devices remaining in categories

    I'm writing a script that determines the devices in a category and I've noticed that the category still contains old devices that I've previously deleted.

    Is there a way I can edit the category to remove those devices?

    This is obviously a bug in HS4 so I will report it to Homeseer but I would like to edit the categories in the meantime.

    #2
    The following script will fix that:

    Code:
    Sub Main(parm as object)
      Dim cats = hs.GetAllCategories()
      Dim catid, refs, ref
    
      hs.WriteLog("CleanCategories", "Removing deleted devices from categories")
    
      For Each catid in cats.Keys
        hs.WriteLog("CleanCategories", "Checking category " & cats(catid))
    
        refs = hs.GetRefsByCategoryId(catid)
        hs.WriteLog("CleanCategories", "- contains " & refs.Count & " refs")
    
        For Each ref in refs
          If Not hs.DeviceExistsRef(ref) Then
            hs.WriteLog("CleanCategories", "- ref " & ref & " does not exist, removing")
            hs.RemoveRefFromCategory(catid, ref)
          End If
        Next
      Next
    
      hs.WriteLog("CleanCategories", "Categories cleaned")
    End Sub

    Comment


      #3
      Originally posted by rge View Post
      The following script will fix that:

      Code:
      Sub Main(parm as object)
      Dim cats = hs.GetAllCategories()
      Dim catid, refs, ref
      
      hs.WriteLog("CleanCategories", "Removing deleted devices from categories")
      
      For Each catid in cats.Keys
      hs.WriteLog("CleanCategories", "Checking category " & cats(catid))
      
      refs = hs.GetRefsByCategoryId(catid)
      hs.WriteLog("CleanCategories", "- contains " & refs.Count & " refs")
      
      For Each ref in refs
      If Not hs.DeviceExistsRef(ref) Then
      hs.WriteLog("CleanCategories", "- ref " & ref & " does not exist, removing")
      hs.RemoveRefFromCategory(catid, ref)
      End If
      Next
      Next
      
      hs.WriteLog("CleanCategories", "Categories cleaned")
      End Sub
      Perfect, thanks so much.

      Comment

      Working...
      X