Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Berry fix rules for string comparisons #18464

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
### Fixed
- ESP8266 Energy Export Active no update regression from v12.3.1.3
- NovaSDS GUI values (#18444)
- Berry fix rules for string comparisons

### Removed

Expand Down
26 changes: 16 additions & 10 deletions lib/libesp32/berry_tasmota/src/embedded/rule_matcher.be
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ tasmota.Rule_Matcher.parse("AA#BB#CC")
tasmota.Rule_Matcher.parse("AA")
# [<Matcher key='AA'>]

tasmota.Rule_Matcher.parse("AA#BB#CC=2")
# [<Matcher key='AA'>, <Matcher key='BB'>, <Matcher key='CC'>, <Matcher op '=' val='2'>]
tasmota.Rule_Matcher.parse("AA#BB#CC==2")
# [<Matcher key='AA'>, <Matcher key='BB'>, <Matcher key='CC'>, <Matcher op '==' val='2'>]

tasmota.Rule_Matcher.parse("AA#BB#CC>=3.5")
# [<Matcher key='AA'>, <Matcher key='BB'>, <Matcher key='CC'>, <Matcher op '>=' val='3.5'>]

tasmota.Rule_Matcher.parse("AA#BB#CC!3.5")
# [<Matcher key='AA'>, <Matcher key='BB'>, <Matcher key='CC!3.5'>]

tasmota.Rule_Matcher.parse("AA#BB#CC==3=5")
# [<Matcher key='AA'>, <Matcher key='BB'>, <Matcher key='CC'>, <Matcher op '==' val='3=5'>]
tasmota.Rule_Matcher.parse("AA#BB#CC=3=5")
# [<Matcher key='AA'>, <Matcher key='BB'>, <Matcher key='CC'>, <Matcher op '=' val='3=5'>]

tasmota.Rule_Matcher.parse("AA#BB#!CC!==3=5")
# [<Matcher key='AA'>, <Matcher key='BB'>, <Matcher key='!CC'>, <Matcher op '!==' val='3=5'>]
Expand All @@ -39,16 +39,16 @@ tasmota.Rule_Matcher.parse("A#?#B")
# [<Matcher key='A'>, <Matcher any>, <Matcher key='B'>]

tasmota.Rule_Matcher.parse("A#?>50")
# [<Matcher key='A'>, <Matcher any>, <Matcher op '>' val='50'>]
# [<Matcher key='A'>, <Matcher any>, <Matcher op '>' val=50>]

tasmota.Rule_Matcher.parse("A[1]")
# [<instance: Rule_Matcher_Key()>, <Matcher [0]>]
# [<Matcher key='A'>, <Matcher [1]>]

tasmota.Rule_Matcher.parse("A[1]#B[2]>3")
# [<instance: Rule_Matcher_Key()>, <Matcher [0]>, <instance: Rule_Matcher_Key()>, <Matcher [0]>, <Matcher op '>' val='3'>]
# [<Matcher key='A'>, <Matcher [1]>, <Matcher key='B'>, <Matcher [2]>, <Matcher op '>' val=3>]

tasmota.Rule_Matcher.parse("A#B[]>3")
# [<instance: Rule_Matcher_Key()>, <instance: Rule_Matcher_Key()>, <Matcher [0]>, <Matcher op '>' val='3'>]
# [<Matcher key='A'>, <Matcher key='B'>, <Matcher [0]>, <Matcher op '>' val=3>]

#################################################################################

Expand All @@ -67,7 +67,13 @@ assert(m.match({'aa':{'bb':1}}) == nil)
assert(m.match({'aa':{'bb':{'cc':1}}}) == nil)
assert(m.match({'aa':{'bb':{'cc':2}}}) == 2)

m = tasmota.Rule_Matcher.parse("AA#?#CC==2")
m = tasmota.Rule_Matcher.parse("AA#BB#CC=Foo")
assert(m.match({'aa':{'bb':{'cc':1}}}) == nil)
assert(m.match({'aa':{'bb':{'cc':'Foo'}}}) == 'Foo')
assert(m.match({'aa':{'bb':{'cc':'foo'}}}) == 'foo')
assert(m.match({'aa':{'bb':{'cc':'foobar'}}}) == nil)

m = tasmota.Rule_Matcher.parse("AA#?#CC=2")
assert(m.match({'aa':1}) == nil)
assert(m.match({'aa':{'bb':{'cc':2}}}) == 2)

Expand Down Expand Up @@ -251,7 +257,7 @@ class Rule_Matcher
self.op_value = val_num
end
else
self.op_value = str(op)
self.op_value = str(op_value)
end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ be_local_closure(Rule_Matcher_Operator_op_parse, /* name */
0x90022C13, // 005A SETMBR R0 K22 R19
0x70020003, // 005B JMP #0060
0x60480008, // 005C GETGBL R18 G8
0x5C4C0200, // 005D MOVE R19 R1
0x5C4C0400, // 005D MOVE R19 R2
0x7C480200, // 005E CALL R18 1
0x90022C12, // 005F SETMBR R0 K22 R18
0x80000000, // 0060 RET 0
Expand Down