Exemplo n.º 1
0
 def handle_n_line(line):
     devices.flush()
     commands.send_sync_package(line)
     for device in devices.devices.values():
         mqtt.publish_stats(device)
         mqtt.publish_availability(device)
         ws.send_device_stats(device)
Exemplo n.º 2
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()
Exemplo 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()
Exemplo n.º 4
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()
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
0
 def update_device_stats(self, stats):
     self.device.set_stats(stats)
     mqtt.publish_stats(self.device)
     mqtt.publish_availability(self.device)
     ws.send_device_stats(self.device)