Skip to content

Commit

Permalink
Zigbee Berry minor fix and cleaning (#19257)
Browse files Browse the repository at this point in the history
* Zigbee Berry minor fix and cleaning

* Fix compilation
  • Loading branch information
s-hadinger committed Aug 5, 2023
1 parent 732e410 commit 362326f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 343 deletions.
79 changes: 9 additions & 70 deletions lib/libesp32/berry_tasmota/src/embedded/zigbee_zcl_attribute.be
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ class zcl_attribute_list : zcl_attribute_list_ntv

var items = []
# {"Device":"0x246D","Name":"Plug","EnergyTotal":"0x000000000000","Endpoint":1,"LinkQuality":229}
var v

# shortaddr
if self.shortaddr != nil
items.push(format('"Device":"0x%04X"', self.shortaddr))
if (v := self.shortaddr) != nil
items.push(f'"Device":"0x{v:04X}"')
end
# groupaddr
if self.groupaddr != nil
items.push(format('"Group":"0x%04X"', self.groupaddr))
if (v := self.groupaddr) != nil
items.push(f'"Group":"0x{v:04X}"')
end

# attributes
Expand All @@ -222,13 +223,13 @@ class zcl_attribute_list : zcl_attribute_list_ntv
end

# Endpoint
if self.src_ep != nil
items.push(format('"Endpoint":%i', self.src_ep))
if (v := self.src_ep) != nil
items.push(f'"Endpoint":{v}')
end

# LQI
if self.lqi != nil
items.push(format('"LinkQuality":%i', self.lqi))
if (v := self.lqi) != nil
items.push(f'"LinkQuality":{v}')
end

var s = "{" + items.concat(",") + "}"
Expand All @@ -238,68 +239,6 @@ class zcl_attribute_list : zcl_attribute_list_ntv
end
end

#@ solidify:zcl_attributes,weak
class zcl_attributes
var shortaddr
var groupaddr
var lqi
var src_ep
var attr_list

def init(shortaddr, groupaddr, lqi, src_ep, attr_list)
self.shortaddr = shortaddr
self.groupaddr = groupaddr
self.lqi = lqi
self.src_ep = src_ep
if isinstance(self.attr_list, list)
self.attr_list = attr_list
else
self.attr_list = []
end
end

def push(attr)
self.attr_list.push(attr)
end

def tostring()
import json

var items = []
# {"Device":"0x246D","Name":"Plug","EnergyTotal":"0x000000000000","Endpoint":1,"LinkQuality":229}

# shortaddr
if self.shortaddr != nil
items.push(format('"Device":"0x%04X"', self.shortaddr))
end
# groupaddr
if self.shortaddr != nil
items.push(format('"Group":"0x%04X"', self.groupaddr))
end

# attributes
for e: self.attr_list
items.push(e.tostring())
end

# Endpoint
if self.src_ep != nil
items.push(format('"Endpoint":%i', self.src_ep))
end

# Endpoint
if self.lqi != nil
items.push(format('"LinkQuality":%i', self.lqi))
end

var s = "{" + items.concat(",") + "}"
return s

# return format("shortaddr:0x%04X groupaddr:0x%04X %s", self.shortaddr, self.groupaddr, str(self.attr_list))
end

end

#-
# Unit tests
Expand Down
Loading

0 comments on commit 362326f

Please sign in to comment.