v8.0.15
Update: I found some strange behaviour in the tagBrowse function I’m using which looks to be the cause… still looking…
I’m not sure if I’m doing something wrong, but these lines are appending the dictionary i’ve created in script onto the end of my properties, instead of replacing the data in the properties… I don’t see an issue when replacing my code with a simple dictionary and setting that to a component property. Look for the “<<<” in the code for specific comments
self.getSibling("ViewCanvas").props.instances = instances
self.view.custom.tags = instances
This is my full code:
def runAction(self, event):
"""
This event is fired when the 'action' of the component occurs.
Arguments:
self: A reference to the component that is invoking this function.
event: An empty event object.
"""
# builds the instances array for the View Canvas component to display the relevant room devices
self.getSibling("ViewCanvas").props.instances = {} # <<< I tried adding this into the start to wipe the property first.. no luck
# get a list of all status tags from the house room devices
statusTags = tags.browseTags(path='[default]House Room Control', filter={'name':"Status"})
# read the status tags and produce a list of values indicating off/on status (false/true)
statusVals = system.tag.readBlocking(statusTags)
statusVals = [tag.value > 0 for tag in statusVals]
statuses = zip(statusTags, statusVals)
# get only the on or the off devices, based on dropdown selection
selectedValue = self.props.value == 'Active'
# get the path to the UDT Instance by removing the last element (the tag) from the path and filter by selection
tagPaths = ['/'.join(str(status[0]).split('/')[0:-1]) for status in statuses if status[1] == selectedValue]
instances = []
prevRoomName = ''
roomName = ''
for path in tagPaths:
# get the config of the tag so we can get its UDTType defintion path
cfg = system.tag.getConfiguration(path)
UDTInst = cfg[0].get('typeId')
# if its a UDT, then add it to the instances list
if UDTInst != None:
# path is in the format: [default]House Room Control/<Room Name>/<Device/Tag Name>
tagParentPath = '/'.join(str(path).split("/")[0:-1])
tagName = str(path).split("/")[-1]
roomName = tagParentPath.split('/')[-1]
# if this is a new room, then add the room name as a subtitle
if roomName != prevRoomName:
item = {}
item['position'] = 'relative'
item['top'] = '0px'
item['left'] = '0px'
item['bottom'] = 'auto'
item['right'] = 'auto'
item['zIndex'] = 'auto'
item['width'] = 'auto'
item['height'] = 'auto'
item['viewPath'] = 'Templates/Cards/Subtitle w Icon'
viewParams = {'title':roomName,'showIcon':0}
item['viewParams'] = viewParams
style = {'classes':''}
item['style'] = style
instances.append(item)
# add the required fields for the instance to a dictionary, then add it into the instances list
item = {}
item['position'] = 'relative'
item['top'] = '0px'
item['left'] = '0px'
item['bottom'] = 'auto'
item['right'] = 'auto'
item['zIndex'] = 'auto'
item['width'] = 'auto'
item['height'] = 'auto'
item['viewPath'] = 'Templates/Room Devices/' + UDTInst.split('/')[-1]
viewParams = {'tagParentPath':tagParentPath,'tagName':tagName}
item['viewParams'] = viewParams
style = {'classes':''}
style["borderBottomColor"] = "#ffffff8A"
style["borderBottomStyle"] = "solid"
style["borderBottomWidth"] = "0.5px"
item['style'] = style
instances.append(item)
prevRoomName = roomName
# set the view canvas' instances to the new dictionary
self.getSibling("ViewCanvas").props.instances = instances # <<< This line should replace the View Canvas instances, however it's appending it to the end of the instances data instead??