Exemplo n.º 1
0
def dimmerState(path):
    if request.method == 'POST':
        data = request.form
        device = data['deviceId']
        if (data['deviceType'] == 'dimmerLevel'):
            status = zp_st.getDeviceStatus('switch', device, 'state')
            if (status == 'on'):
                level = data['level']
                zp_st.setDimmer(device, level)

            return Response(json.dumps({'error': 1}))

        if (data['deviceType'] == 'switch'):
            zp_st.toggleSwitch(device)
            status = zp_st.getDeviceStatus('switch', device, 'state')
            if (status == 'on'):
                status = 'off'
            else:
                status = 'on'

            return Response(json.dumps({'error': 1, 'switch': status}))

    else:
        device = unquote(path)
        state = zp_st.getDeviceStatus('dimmer', device, 'state')
        level = zp_st.getDeviceStatus('dimmer', device, 'level')
        results = {'state': state, 'level': level}
        return Response(json.dumps(results))
Exemplo n.º 2
0
def switchState(path):
    if request.method == 'POST':
        data = request.form
        device = data['deviceId']
        zp_st.toggleSwitch(device)
        status = zp_st.getDeviceStatus('switch', device, 'state')
        if (status == 'on'):
            status = 'off'
        else:
            status = 'on'
        return Response(json.dumps({'error': 1, 'switch': status}))
    else:
        device = unquote(path)
        status = zp_st.getDeviceStatus('switch', device, 'state')
        results = {'switch': status}
        return Response(json.dumps(results))