add testing files and mqtt and table modules

master
David Kebler 2023-12-27 08:59:44 -08:00
parent 46e295451e
commit 67259f40ef
15 changed files with 387 additions and 7 deletions

14
bundle
View File

@ -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

25
mqttx.be Normal file
View File

@ -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

39
table.be Normal file
View File

@ -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

11
test/hasetup.be Normal file
View File

@ -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)

38
test/mqttx.tst.be Normal file
View File

@ -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

28
test/subobjtst.be Normal file
View File

@ -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

15
test/table-dev.be Normal file
View File

@ -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

82
test/table.json Normal file
View File

@ -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"
}
}

98
test/tablelist.json Normal file
View File

@ -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"
}
]

9
test/test copy.json Normal file
View File

@ -0,0 +1,9 @@
{
"key2": 2,
"key1": {
"subkey1": {
"test": 1
},
"subkey2": 2
}
}

19
test/test-object.be Normal file
View File

@ -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')

1
test/test.cfg Normal file
View File

@ -0,0 +1 @@
{"changedkey":2,"key1":{"another":{"deep":{"key":[1,2,3,4]}},"subkey2":2,"subkey1":{"test":1}}}

1
test/test.json Normal file
View File

@ -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"}}

1
test/test2.json Normal file
View File

@ -0,0 +1 @@
{"two":2,"one":1}

13
test/test2obj.be Normal file
View File

@ -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())