Example #1
0
async def firstrun(client):
    firstrun = False
    await asyncio.sleep(10)
    if firstrun == False:
        await client.publish(config['maintopic'] + '/doinit', "firstrun")
        hpfuncs.logprint("init firstrun")
        firstrun = True
    while True:
        await asyncio.sleep(60)
        await client.publish(config['maintopic'] + '/watchdog', "get")
        hpfuncs.logprint("running watchdog..")
Example #2
0
def sub_cb(topic, msg, retained):
    global power_state
    runwrite = True
    hpfuncs.logprint(str(topic) + " -- " + str(msg))
    ################################################
    #setpoint
    if topic == topic_sub_setp:
        try:
            values = hpfuncs.setpointVal(int(float(msg)))
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################
#restart
    if topic == topic_sub_restart:
        try:
            machine.reset()
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################
# state
    elif topic == topic_sub_state:
        try:
            values = hpfuncs.stateControl(msg)
            if values == False:
                runwrite = False
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################
# swingstate
    elif topic == topic_sub_swingmode:
        try:
            values = hpfuncs.swingControl(msg)
            if values == False:
                runwrite = False
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################
# mode
    elif topic == topic_sub_mode:
        try:
            values = hpfuncs.modeControl(msg)
            if values == False:
                runwrite = False
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################
# fanmode
    elif topic == topic_sub_fanmode:
        try:
            values = hpfuncs.fanControl(msg)
            if values == False:
                runwrite = False
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################
# do init
    elif topic == topic_sub_doinit:
        myvals = hpfuncs.queryall()
        hpfuncs.logprint("initial read")
        for i in myvals:
            uart.write(bytearray(i))
            sleep(0.2)
        hpfuncs.logprint("initial read done")
        runwrite = False

################################################
# do watchdog
    elif topic == topic_sub_watchdog:
        myvals = hpfuncs.watchdog()
        for i in myvals:
            uart.write(bytearray(i))
            sleep(0.2)
        runwrite = False


################################################
    if runwrite == True and values != False:
        #print(values)
        for i in values:
            hpfuncs.logprint("writing: " + str(i))
            uart.write(bytearray(i))
            sleep(0.2)
Example #3
0
async def receiver(client):
    global power_state

    sreader = asyncio.StreamReader(uart)
    try:
        while True:
            serdata = await sreader.read(2048)
            if serdata is not None:
                readable = list()
                for i in serdata:
                    readable.append(str(int(i)))
                hpfuncs.logprint("length of data: " + str(len(readable)))
                chunks = chunkifyarray(readable)
                for data in chunks:
                    hpfuncs.logprint(data)
                    await client.publish(
                        config['maintopic'] + '/debug/fullstring', str(data))
                    if len(data) == 17:
                        if (str(data[14]) == "187"):
                            roomtemp = int_to_signed(int(data[15]))
                            await client.publish(config['maintopic'] +
                                                 '/roomtemp',
                                                 str(roomtemp),
                                                 qos=1)
                        if (str(data[14]) == "179"):
                            setpoint = int(data[15])
                            await client.publish(config['maintopic'] +
                                                 '/setpoint/state',
                                                 str(setpoint),
                                                 qos=1)
                        if (str(data[14]) == "128"):
                            state = hpfuncs.inttostate[int(data[15])]
                            power_state = state
                            await client.publish(config['maintopic'] +
                                                 '/state/state',
                                                 str(state),
                                                 qos=1)
                            if (state == "OFF"):
                                # when power state is OFF, sent unit mode also as "off"
                                await client.publish(config['maintopic'] +
                                                     '/mode/state',
                                                     "off",
                                                     qos=1)
                        if (str(data[14]) == "160"):
                            fanmode = hpfuncs.inttofanmode[int(data[15])]
                            await client.publish(config['maintopic'] +
                                                 '/fanmode/state',
                                                 str(fanmode),
                                                 qos=1)
                        if (str(data[14]) == "163"):
                            swingmode = hpfuncs.inttoswing[int(data[15])]
                            await client.publish(config['maintopic'] +
                                                 '/swingmode/state',
                                                 str(swingmode),
                                                 qos=1)
                        if (str(data[14]) == "176"):
                            mode = hpfuncs.inttomode[int(data[15])]
                            # report actual mode when unit is running or "off" when it's not
                            reportedState = str(mode) if (power_state
                                                          == "ON") else "off"
                            await client.publish(config['maintopic'] +
                                                 '/mode/state',
                                                 reportedState,
                                                 qos=1)
                        if (str(data[14]) == "190"):
                            outdoortemp = int_to_signed(int(data[15]))
                            await client.publish(config['maintopic'] +
                                                 '/outdoortemp',
                                                 str(outdoortemp),
                                                 qos=1)
                    elif len(data) == 15:
                        if (str(data[12]) == "187"):
                            roomtemp = int_to_signed(int(data[13]))
                            await client.publish(config['maintopic'] +
                                                 '/roomtemp',
                                                 str(roomtemp),
                                                 qos=1)
                        if (str(data[12]) == "179"):
                            setpoint = int(data[13])
                            await client.publish(config['maintopic'] +
                                                 '/setpoint/state',
                                                 str(setpoint),
                                                 qos=1)
                        if (str(data[12]) == "128"):
                            state = hpfuncs.inttostate[int(data[13])]
                            power_state = state
                            await client.publish(config['maintopic'] +
                                                 '/state/state',
                                                 str(state),
                                                 qos=1)
                            if (state == "OFF"):
                                # when power state is OFF, sent unit mode also as "off"
                                await client.publish(config['maintopic'] +
                                                     '/mode/state',
                                                     "off",
                                                     qos=1)
                        if (str(data[12]) == "160"):
                            fanmode = hpfuncs.inttofanmode[int(data[13])]
                            await client.publish(config['maintopic'] +
                                                 '/fanmode/state',
                                                 str(fanmode),
                                                 qos=1)
                        if (str(data[12]) == "163"):
                            swingmode = hpfuncs.inttoswing[int(data[13])]
                            await client.publish(config['maintopic'] +
                                                 '/swingmode/state',
                                                 str(swingmode),
                                                 qos=1)
                        if (str(data[12]) == "176"):
                            mode = hpfuncs.inttomode[int(data[13])]
                            # report actual mode when unit is running or "off" when it's not
                            reportedState = str(mode) if (power_state
                                                          == "ON") else "off"
                            await client.publish(config['maintopic'] +
                                                 '/mode/state',
                                                 reportedState,
                                                 qos=1)
                        if (str(data[12]) == "190"):
                            outdoortemp = int_to_signed(int(data[13]))
                            await client.publish(config['maintopic'] +
                                                 '/outdoortemp',
                                                 str(outdoortemp),
                                                 qos=1)

    except Exception as e:
        hpfuncs.logprint(e)
Example #4
0
def sub_cb(topic, msg, retained):
    global power_state
    runwrite = True
    hpfuncs.logprint(str(topic) + " -- " + str(msg))
################################################ 
#setpoint
    if topic == topic_sub_setp:
        try:
            values = hpfuncs.setpointVal(int(float(msg)))
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################ 
#restart
    if topic == topic_sub_restart:
        try:
            machine.reset()
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False            
################################################        
# state
    elif topic == topic_sub_state:
        try:
            values = hpfuncs.stateControl(msg)
            if values == False:
                runwrite = False
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################        
# swingstate
    elif topic == topic_sub_swingmode:
        try:
            values = hpfuncs.swingControl(msg)
            if values == False:
                runwrite = False
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################        
# mode
    elif topic == topic_sub_mode:
        try:
            message = msg.decode("utf-8")
            # mode switched to off, power off unit
            if (message == "off"):
                values = hpfuncs.stateControl("OFF")
            else:
                if power_state != 'ON':
                    # unit is OFF and some other mode was selected
                    values = hpfuncs.stateControl("ON")
                    values = values + hpfuncs.modeControl(msg)
                else:
                    # changed mode of running A/C
                    values = hpfuncs.modeControl(msg)
            if values == False:
                runwrite = False
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################
# fanmode
    elif topic == topic_sub_fanmode:
        try:
            values = hpfuncs.fanControl(msg)
            if values == False:
                runwrite = False
        except Exception as e:
            hpfuncs.logprint(e)
            runwrite = False
################################################
# do init
    elif topic == topic_sub_doinit:
        myvals = hpfuncs.queryall()
        hpfuncs.logprint("initial read")
        for i in myvals:
            uart.write(bytearray(i))
            sleep(0.2)
        hpfuncs.logprint("initial read done")
        runwrite = False
################################################
# do watchdog
    elif topic == topic_sub_watchdog:
        myvals = hpfuncs.watchdog()
        for i in myvals:
            uart.write(bytearray(i))
            sleep(0.2)
        runwrite = False
################################################ 
    if runwrite == True and values != False:
        #print(values)
        for i in values:
            hpfuncs.logprint("writing: " + str(i))
            uart.write(bytearray(i))
            sleep(0.2)