Ejemplo n.º 1
0
 def cancel_commands(addr):
     try:
         if devices.is_remote_device(addr):
             RemoteController.redirect_command(request, addr)
         else:
             device = devices.get_device(addr)
             device.cancel_commands()
             mqtt.publish_availability(device)
             ws.send_device_stats(device)
     except KeyError:
         pass
     print(' < HTTP: {} cancel_commands'.format(addr))
     sys.stdout.flush()
Ejemplo n.º 2
0
 def settings(addr):
     try:
         if devices.is_remote_device(addr):
             settings = devices.get_device_from_remote(addr).settings
         else:
             settings = devices.get_device(addr).settings
         if 'ff' in settings:
             layout = get_eeprom_layout(int('0x' + settings['ff'], 16))
             return template('settings',
                             title='Settings',
                             layout=layout,
                             device_settings=settings)
     except KeyError:
         pass
     print(' < HTTP: {} settings'.format(addr))
Ejemplo n.º 3
0
 def set_settings(addr):
     try:
         if devices.is_remote_device(addr):
             RemoteController.redirect_command(request, addr)
         else:
             device = devices.get_device(addr)
             for idx, value in device.settings.items():
                 new = request.json.get(idx)
                 if new != value:
                     device.send_setting(idx, new)
             mqtt.publish_availability(device)
             ws.send_device_stats(device)
     except KeyError:
         pass
     print(' < HTTP: {} set_settings'.format(addr))
     sys.stdout.flush()
Ejemplo n.º 4
0
 def timers(addr):
     try:
         if devices.is_remote_device(addr):
             device = devices.get_device_from_remote(addr)
         else:
             device = devices.get_device(addr)
         mode = device.settings['22']
         mode = 1 if mode is not None and int(mode, 16) > 0 else 0
         preset0 = device.settings['01']
         preset1 = device.settings['02']
         preset2 = device.settings['03']
         preset3 = device.settings['04']
         presets = [
             {
                 'id': 0,
                 'name': 'Frost',
                 'temp': preset0 if preset0 is not None else '00'
             },
             {
                 'id': 1,
                 'name': 'Eco',
                 'temp': preset1 if preset1 is not None else '00'
             },
             {
                 'id': 2,
                 'name': 'Comfort',
                 'temp': preset2 if preset2 is not None else '00'
             },
             {
                 'id': 3,
                 'name': 'Super Comfort',
                 'temp': preset3 if preset3 is not None else '00'
             },
         ]
         return template('timers',
                         title='Timers',
                         mode=mode,
                         timers=device.timers,
                         presets=presets)
     except KeyError:
         pass
     print(' < HTTP: {} timers'.format(addr))
Ejemplo n.º 5
0
 def set_timers(addr):
     try:
         if devices.is_remote_device(addr):
             RemoteController.redirect_command(request, addr)
         else:
             device = devices.get_device(addr)
             timers = device.timers
             for day, value in request.json['timers'].items():
                 if timers[int(day[0])][int(day[1])] != value:
                     device.send_timer(day, value)
             new_mode = int(request.json['mode'])
             if new_mode != (0
                             if int(device.settings['22'], 16) == 0 else 1):
                 device.send_setting('22', '{:02x}'.format(new_mode))
             mqtt.publish_availability(device)
             ws.send_device_stats(device)
     except KeyError:
         pass
     print(' < HTTP: {} set_timers'.format(addr))
     sys.stdout.flush()
Ejemplo n.º 6
0
 def set_mode(addr):
     mode = request.json.get('mode')
     try:
         if devices.is_remote_device(addr):
             RemoteController.redirect_command(request, addr)
         else:
             device = devices.get_device(addr)
             device.set_mode(mode)
             if device.group is not None:
                 for dev in device.group.devices:
                     mqtt.publish_availability(dev)
                     ws.send_device_stats(dev)
             else:
                 mqtt.publish_availability(device)
                 ws.send_device_stats(device)
     except KeyError:
         pass
     except ValueError:
         pass
     print(' < HTTP: {} mode {}'.format(addr, mode))
     sys.stdout.flush()
Ejemplo n.º 7
0
    def set_temp(addr):
        temp = float(request.json.get('temp'))
        try:
            if devices.is_remote_device(addr):
                RemoteController.redirect_command(request, addr)
            else:
                device = devices.get_device(addr)
                device.set_temperature(temp)
                if device.group is not None:
                    for dev in device.group.devices:
                        mqtt.publish_availability(dev)
                        ws.send_device_stats(dev)
                else:
                    mqtt.publish_availability(device)
                    ws.send_device_stats(device)

        except KeyError:
            pass
        except ValueError:
            pass
        print(' < HTTP: {} temp {}'.format(addr, temp))
        sys.stdout.flush()