diff --git a/bundle b/bundle index 80bb76a..6d824b7 100755 --- a/bundle +++ b/bundle @@ -1,12 +1,12 @@ #!/bin/bash # todo set utility directory and also customize start.be -MODULES=/data/coding/berry/modules +# MODULES=/data/coding/berry/modules # todo bash lower case no space function rm ./utils.tapp -zip -j -Z store ./utils.tapp \ -$MODULES/util/stringe.be \ -$MODULES/util/file.be \ -$MODULES/util/object.be \ -$MODULES/util/time.be \ -$MODULES/util/ha.be +zip -j -Z store ../utils.tapp \ +stringe.be \ +file.be \ +object.be \ +time.be \ +ha.be diff --git a/mqttx.be b/mqttx.be new file mode 100644 index 0000000..5474f39 --- /dev/null +++ b/mqttx.be @@ -0,0 +1,25 @@ +var mqttx = module("mqttx") + +def mqtt_wait(con,dis) + if dis dis() end + mqttx.connected = false + tasmota.remove_rule("mqtt#disconnected",2) + tasmota.add_rule("mqtt#connected", /-> mqttx.ready(con,dis),2) +end + +def mqtt_ready(con,dis) + mqttx.connected=true + if con con() end + tasmota.remove_rule("mqtt#connected",2) + tasmota.add_rule("mqtt#disconnected", /-> mqttx.wait(con,dis),2) +end + +mqttx.connected = false +mqttx.wait = mqtt_wait +mqttx.ready = mqtt_ready + +print(tasmota.millis()) + +return mqttx + + diff --git a/table.be b/table.be new file mode 100644 index 0000000..948aaad --- /dev/null +++ b/table.be @@ -0,0 +1,39 @@ +# lookup table loaded from json + +import json +import os +path=os.path + +# class Table + +# var filename +# var tbl + # def init(name,opts) + # self.load() + # end + +def load(filename) + + var f # file object + var tbl # values loaded from json + + filename=filename+'.json' + + if path.exists(filename) + print(filename) + try + f = open(filename, "r") + tbl = json.load(f.read()) + f.close() + except .. as e, m + if f != nil f.close() end + raise e, m + end + print('returning table',tbl) + return tbl + end +end + +var table = module('table') +table.load = load +return table \ No newline at end of file diff --git a/test/hasetup.be b/test/hasetup.be new file mode 100644 index 0000000..6b8032f --- /dev/null +++ b/test/hasetup.be @@ -0,0 +1,11 @@ +debug = [false,false,false,false] + +import ha + +opts = {'jsonkey':'speed','icon':'mid:weather-windy','topic_prefix':'weather', 'unit':'MPH'} +custom = {'test':'another key'} +opts.setitem('custom',custom) + +print(opts) + +ha.entity_create('Wind Speed',opts) \ No newline at end of file diff --git a/test/mqttx.tst.be b/test/mqttx.tst.be new file mode 100644 index 0000000..ab916cf --- /dev/null +++ b/test/mqttx.tst.be @@ -0,0 +1,38 @@ +import mqttx as mqtt +import introspect + +print(introspect(mqtt.ready),introspect(mqtt.wait)) + + +# def mqtt_connected_cmds() +# tasmota.add_rule("Tele#DS18B20#Temperature", pub_temperature,2) +# tasmota.add_rule("mqtt#connected",/-> subscribe_cntrl() ,2) + +# tasmota.cmd("Subscribe "+self.cfg.id,"/weather/set/"+self.cfg.id) +# tasmota.add_rule("Event#weather"+self.cfg.id, /-> self.mqtt_process_cmd()) +# end + +# def mqtt_disconnected_cmds() +# tasmota.remove_rule("Event#weather"+self.cfg.id, 2) +# end + +# def subscribe_cntrl() +# print("subscribing to stoneroom via mqtt") +# mqtt.subscribe("stoneroom/cntrl/#", process_cmd) +# tasmota.remove_rule("mqtt#connected",2) +# end + + +# def process_cmd (topic,idx,payload,bytes) +# print('topic:', topic,idx, 'payload is:', payload, bytes) +# if payload +# var mcmd = json.load(payload) +# print (mcmd.find('relay'), mcmd.find('state')) +# var scmd = 'power'+str(mcmd.find('relay'))+' '+str(mcmd.find('state') == "OFF" ? 0 : 1) +# print(scmd) +# tasmota.cmd(scmd) +# return true +# else +# return false +# end +# end \ No newline at end of file diff --git a/test/subobjtst.be b/test/subobjtst.be new file mode 100644 index 0000000..3501395 --- /dev/null +++ b/test/subobjtst.be @@ -0,0 +1,28 @@ +debug = false +debug2 = false + +############################################################# +# only for development start on dev machine +import sys +sys.path().push('/data/coding/berry/modules/util') +sys.path().push('/data/coding/berry/modules/dev') +print(sys.path()) +########################################################## + +import object + +var datafile = 'test.dat' +var more = object({}) +# use parent parameter to track use with save and load. +var data = object(datafile,{'autoload':false, 'sobj':['more']}) #sobj are maps to be treated as objects +if path.exists(datafile) + data.load() + else + data.max = 10 + data.more = {} +end +more.assign(data.more) +data._autosave = true + + + diff --git a/test/table-dev.be b/test/table-dev.be new file mode 100644 index 0000000..5a0b1c9 --- /dev/null +++ b/test/table-dev.be @@ -0,0 +1,15 @@ +import table +import math +t = table.load('tablelist') +val = 2656 +for e:t + # print(e) + setpoint = e.item('RAW') + print('checking',val,setpoint) + if math.abs(setpoint - val) < 20 + print('matched') + print (e) + end +end +# for e:i print(e) end + diff --git a/test/table.json b/test/table.json new file mode 100644 index 0000000..8bea4c5 --- /dev/null +++ b/test/table.json @@ -0,0 +1,82 @@ +{ + "115": { + "CW": 112.5, + "CCW": 247.5, + "Direction": "ESE" + }, + "187": { + "CW": 67.5, + "CCW": 292.5, + "Direction": "ENE" + }, + "223": { + "CW": 90, + "CCW": 270, + "Direction": "E" + }, + "352": { + "CW": 157.5, + "CCW": 202.5, + "Direction": "SSE" + }, + "588": { + "CW": 135, + "CCW": 225, + "Direction": "SE" + }, + "829": { + "CW": 202.5, + "CCW": 157.5, + "Direction": "SSW" + }, + "1000": { + "CW": 180, + "CCW": 180, + "Direction": "S" + }, + "1483": { + "CW": 22.5, + "CCW": 337.5, + "Direction": "NNE" + }, + "1707": { + "CW": 45, + "CCW": 315, + "Direction": "NE" + }, + "2260": { + "CW": 247.5, + "CCW": 112.5, + "Direction": "WSW" + }, + "2383": { + "CW": 225, + "CCW": 135, + "Direction": "SW" + }, + "2675": { + "CW": 337.5, + "CCW": 22.5, + "Direction": "NNW" + }, + "3025": { + "CW": 0, + "CCW": 360, + "Direction": "N" + }, + "3216": { + "CW": 292.5, + "CCW": 67.5, + "Direction": "WNW" + }, + "3532": { + "CW": 315, + "CCW": 45, + "Direction": "NW" + }, + "3923": { + "CW": 270, + "CCW": 90, + "Direction": "W" + } +} \ No newline at end of file diff --git a/test/tablelist.json b/test/tablelist.json new file mode 100644 index 0000000..1fb594b --- /dev/null +++ b/test/tablelist.json @@ -0,0 +1,98 @@ +[ + { + "RAW": 3025, + "CW": 0, + "CCW": 360, + "Direction": "N" + }, + { + "RAW": 1483, + "CW": 22.5, + "CCW": 337.5, + "Direction": "NNE" + }, + { + "RAW": 1707, + "CW": 45, + "CCW": 315, + "Direction": "NE" + }, + { + "RAW": 187, + "CW": 67.5, + "CCW": 292.5, + "Direction": "ENE" + }, + { + "RAW": 223, + "CW": 90, + "CCW": 270, + "Direction": "E" + }, + { + "RAW": 115, + "CW": 112.5, + "CCW": 247.5, + "Direction": "ESE" + }, + { + "RAW": 588, + "CW": 135, + "CCW": 225, + "Direction": "SE" + }, + { + "RAW": 352, + "CW": 157.5, + "CCW": 202.5, + "Direction": "SSE" + }, + { + "RAW": 1000, + "CW": 180, + "CCW": 180, + "Direction": "S" + }, + { + "RAW": 829, + "CW": 202.5, + "CCW": 157.5, + "Direction": "SSW" + }, + { + "RAW": 2383, + "CW": 225, + "CCW": 135, + "Direction": "SW" + }, + { + "RAW": 2260, + "CW": 247.5, + "CCW": 112.5, + "Direction": "WSW" + }, + { + "RAW": 3923, + "CW": 270, + "CCW": 90, + "Direction": "W" + }, + { + "RAW": 3216, + "CW": 292.5, + "CCW": 67.5, + "Direction": "WNW" + }, + { + "RAW": 3532, + "CW": 315, + "CCW": 45, + "Direction": "NW" + }, + { + "RAW": 2675, + "CW": 337.5, + "CCW": 22.5, + "Direction": "NNW" + } +] \ No newline at end of file diff --git a/test/test copy.json b/test/test copy.json new file mode 100644 index 0000000..a7123a6 --- /dev/null +++ b/test/test copy.json @@ -0,0 +1,9 @@ +{ + "key2": 2, + "key1": { + "subkey1": { + "test": 1 + }, + "subkey2": 2 + } +} \ No newline at end of file diff --git a/test/test-object.be b/test/test-object.be new file mode 100644 index 0000000..a4bbe7c --- /dev/null +++ b/test/test-object.be @@ -0,0 +1,19 @@ +import object +import file + +debug = 1 +debug2 = 0 + +var o = object('test') +var o2 = object({'one':1,'two':2},'test2') +var key = 'key1.another.some' +var value = ['a',1,'b'] +# o.set(key,value) +o.set('config',o2.exporti(true)) +print(o.retrieve()) +# print('getting that deep key element 2', key, o.get(key)[1]) +var o3 = o.importi(o.get('config')) +print('after import', o3.retrieve()) +# print('last element',o.get(key)[3]) +o.save() +# o.save('test.cfg') diff --git a/test/test.cfg b/test/test.cfg new file mode 100644 index 0000000..77a20c8 --- /dev/null +++ b/test/test.cfg @@ -0,0 +1 @@ +{"changedkey":2,"key1":{"another":{"deep":{"key":[1,2,3,4]}},"subkey2":2,"subkey1":{"test":1}}} \ No newline at end of file diff --git a/test/test.json b/test/test.json new file mode 100644 index 0000000..1db0e53 --- /dev/null +++ b/test/test.json @@ -0,0 +1 @@ +{"changeup":{"another":{"some":["a",1,"b"],"deep":{"key":[1,2,3,4]}},"subkey2":2,"subkey1":{"test":1}},"key2":2,"newkey":{"test":"adding key with dot"}} \ No newline at end of file diff --git a/test/test2.json b/test/test2.json new file mode 100644 index 0000000..6d7ac55 --- /dev/null +++ b/test/test2.json @@ -0,0 +1 @@ +{"two":2,"one":1} \ No newline at end of file diff --git a/test/test2obj.be b/test/test2obj.be new file mode 100644 index 0000000..f7c0615 --- /dev/null +++ b/test/test2obj.be @@ -0,0 +1,13 @@ +import object +import file + +debug = 0 +debug2 = 0 + +var o = object('test',{'autosave':true}) +print(o.get()) +# print(o.get('key1.another.deep.key')[3]) +# var o2 = object(o.key1) +# print(o2.another) +o.newkey = {'test':'adding key with dot'} +# print(o.get()) \ No newline at end of file