From 5a269ef284fe0668cd6137f8ab1047cf7b80061b Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Fri, 30 Nov 2018 13:46:15 +0100 Subject: [PATCH] Remove old checks --- esphomeyaml/__main__.py | 22 +-------------------- esphomeyaml/core.py | 1 - esphomeyaml/dashboard/dashboard.py | 19 +++++++----------- esphomeyaml/dashboard/static/esphomeyaml.js | 2 +- esphomeyaml/helpers.py | 3 --- esphomeyaml/mqtt.py | 2 -- esphomeyaml/util.py | 6 ++---- 7 files changed, 11 insertions(+), 44 deletions(-) diff --git a/esphomeyaml/__main__.py b/esphomeyaml/__main__.py index f26c619151..1b2b9e682c 100644 --- a/esphomeyaml/__main__.py +++ b/esphomeyaml/__main__.py @@ -86,8 +86,6 @@ def run_miniterm(config, port): line = raw.replace('\r', '').replace('\n', '') time = datetime.now().time().strftime('[%H:%M:%S]') message = time + line - if core.FROM_DASHBOARD: - message = message.replace('\033', '\\033') safe_print(message) backtrace_state = platformio_api.process_stacktrace( @@ -157,7 +155,7 @@ def upload_program(config, args, port): # if upload is to a serial port use platformio, otherwise assume ota serial_port = port.startswith('/') or port.startswith('COM') if port != 'OTA' and serial_port: - if CORE.is_esp8266 and args.dashboard: + if CORE.is_esp8266: return upload_using_esptool(config, port) return platformio_api.run_upload(config, args.verbose, port) @@ -394,24 +392,18 @@ def parse_args(argv): subparsers = parser.add_subparsers(help='Commands', dest='command') subparsers.required = True config = subparsers.add_parser('config', help='Validate the configuration and spit it out.') - config.add_argument('--dashboard', help="Internal flag used by the dashboard", - action='store_true') parser_compile = subparsers.add_parser('compile', help='Read the configuration and compile a program.') parser_compile.add_argument('--only-generate', help="Only generate source code, do not compile.", action='store_true') - parser_compile.add_argument('--dashboard', help="Internal flag used by the dashboard", - action='store_true') parser_upload = subparsers.add_parser('upload', help='Validate the configuration ' 'and upload the latest binary.') parser_upload.add_argument('--upload-port', help="Manually specify the upload port to use. " "For example /dev/cu.SLAB_USBtoUART.") parser_upload.add_argument('--host-port', help="Specify the host port.", type=int) - parser_upload.add_argument('--dashboard', help="Internal flag used by the dashboard", - action='store_true') parser_logs = subparsers.add_parser('logs', help='Validate the configuration ' 'and show all MQTT logs.') @@ -421,8 +413,6 @@ def parse_args(argv): parser_logs.add_argument('--client-id', help='Manually set the client id.') parser_logs.add_argument('--serial-port', help="Manually specify a serial port to use" "For example /dev/cu.SLAB_USBtoUART.") - parser_logs.add_argument('--dashboard', help="Internal flag used by the dashboard", - action='store_true') parser_run = subparsers.add_parser('run', help='Validate the configuration, create a binary, ' 'upload it, and start MQTT logs.') @@ -435,8 +425,6 @@ def parse_args(argv): parser_run.add_argument('--username', help='Manually set the MQTT username for logs.') parser_run.add_argument('--password', help='Manually set the MQTT password for logs.') parser_run.add_argument('--client-id', help='Manually set the client id for logs.') - parser_run.add_argument('--dashboard', help="Internal flag used by the dashboard", - action='store_true') parser_clean = subparsers.add_parser('clean-mqtt', help="Helper to clear an MQTT topic from " "retain messages.") @@ -444,8 +432,6 @@ def parse_args(argv): parser_clean.add_argument('--username', help='Manually set the username.') parser_clean.add_argument('--password', help='Manually set the password.') parser_clean.add_argument('--client-id', help='Manually set the client id.') - parser_clean.add_argument('--dashboard', help="Internal flag used by the dashboard", - action='store_true') subparsers.add_parser('wizard', help="A helpful setup wizard that will guide " "you through setting up esphomeyaml.") @@ -455,8 +441,6 @@ def parse_args(argv): subparsers.add_parser('version', help="Print the esphomeyaml version and exit.") clean = subparsers.add_parser('clean', help="Delete all temporary build files.") - clean.add_argument('--dashboard', help="Internal flag used by the dashboard", - action='store_true') dashboard = subparsers.add_parser('dashboard', help="Create a simple web server for a dashboard.") @@ -474,16 +458,12 @@ def parse_args(argv): hass_config = subparsers.add_parser('hass-config', help="Dump the configuration entries that should be added " "to Home Assistant when not using MQTT discovery.") - hass_config.add_argument('--dashboard', help="Internal flag used by the dashboard", - action='store_true') return parser.parse_args(argv[1:]) def run_esphomeyaml(argv): args = parse_args(argv) - if hasattr(args, 'dashboard'): - core.FROM_DASHBOARD = args.dashboard setup_log(args.verbose) if args.command in PRE_CONFIG_ACTIONS: diff --git a/esphomeyaml/core.py b/esphomeyaml/core.py index 51b6db5457..a2a874f98b 100644 --- a/esphomeyaml/core.py +++ b/esphomeyaml/core.py @@ -423,4 +423,3 @@ CORE = EsphomeyamlCore() ConfigType = Dict[str, Any] CoreType = EsphomeyamlCore -FROM_DASHBOARD = False diff --git a/esphomeyaml/dashboard/dashboard.py b/esphomeyaml/dashboard/dashboard.py index 86f4c48b99..085433941a 100644 --- a/esphomeyaml/dashboard/dashboard.py +++ b/esphomeyaml/dashboard/dashboard.py @@ -78,10 +78,6 @@ class EsphomeyamlCommandWebSocket(tornado.websocket.WebSocketHandler): data = yield self.proc.stdout.read_until_regex('[\n\r]') except tornado.iostream.StreamClosedError: break - try: - data = data.replace('\033', '\\033') - except UnicodeDecodeError: - data = data.encode('ascii', 'backslashreplace') self.write_message({'event': 'line', 'data': data}) def proc_on_exit(self, returncode): @@ -103,50 +99,49 @@ class EsphomeyamlLogsHandler(EsphomeyamlCommandWebSocket): def build_command(self, message): js = json.loads(message) config_file = CONFIG_DIR + '/' + js['configuration'] - return ["esphomeyaml", config_file, "logs", '--serial-port', js["port"], '--dashboard'] + return ["esphomeyaml", config_file, "logs", '--serial-port', js["port"]] class EsphomeyamlRunHandler(EsphomeyamlCommandWebSocket): def build_command(self, message): js = json.loads(message) config_file = os.path.join(CONFIG_DIR, js['configuration']) - return ["esphomeyaml", config_file, "run", '--upload-port', js["port"], - '--dashboard'] + return ["esphomeyaml", config_file, "run", '--upload-port', js["port"]] class EsphomeyamlCompileHandler(EsphomeyamlCommandWebSocket): def build_command(self, message): js = json.loads(message) config_file = os.path.join(CONFIG_DIR, js['configuration']) - return ["esphomeyaml", config_file, "compile", '--dashboard'] + return ["esphomeyaml", config_file, "compile"] class EsphomeyamlValidateHandler(EsphomeyamlCommandWebSocket): def build_command(self, message): js = json.loads(message) config_file = os.path.join(CONFIG_DIR, js['configuration']) - return ["esphomeyaml", config_file, "config", '--dashboard'] + return ["esphomeyaml", config_file, "config"] class EsphomeyamlCleanMqttHandler(EsphomeyamlCommandWebSocket): def build_command(self, message): js = json.loads(message) config_file = os.path.join(CONFIG_DIR, js['configuration']) - return ["esphomeyaml", config_file, "clean-mqtt", '--dashboard'] + return ["esphomeyaml", config_file, "clean-mqtt"] class EsphomeyamlCleanHandler(EsphomeyamlCommandWebSocket): def build_command(self, message): js = json.loads(message) config_file = os.path.join(CONFIG_DIR, js['configuration']) - return ["esphomeyaml", config_file, "clean", '--dashboard'] + return ["esphomeyaml", config_file, "clean"] class EsphomeyamlHassConfigHandler(EsphomeyamlCommandWebSocket): def build_command(self, message): js = json.loads(message) config_file = os.path.join(CONFIG_DIR, js['configuration']) - return ["esphomeyaml", config_file, "hass-config", '--dashboard'] + return ["esphomeyaml", config_file, "hass-config"] class SerialPortRequestHandler(BaseHandler): diff --git a/esphomeyaml/dashboard/static/esphomeyaml.js b/esphomeyaml/dashboard/static/esphomeyaml.js index 35fdc07909..de5fd72b92 100644 --- a/esphomeyaml/dashboard/static/esphomeyaml.js +++ b/esphomeyaml/dashboard/static/esphomeyaml.js @@ -15,7 +15,7 @@ const initializeColorState = () => { }; const colorReplace = (pre, state, text) => { - const re = /(?:\033|\\033)(?:\[(.*?)[@-~]|\].*?(?:\007|\033\\))/g; + const re = /\033(?:\[(.*?)[@-~]|\].*?(?:\007|\033\\))/g; let i = 0; if (state.carriageReturn) { diff --git a/esphomeyaml/helpers.py b/esphomeyaml/helpers.py index 704b22188a..11e3148102 100644 --- a/esphomeyaml/helpers.py +++ b/esphomeyaml/helpers.py @@ -50,7 +50,6 @@ def cpp_string_escape(string, encoding='utf-8'): def color(the_color, message=''): - from esphomeyaml import core from colorlog.escape_codes import escape_codes, parse_colors if not message: @@ -58,8 +57,6 @@ def color(the_color, message=''): else: res = parse_colors(the_color) + message + escape_codes['reset'] - if core.FROM_DASHBOARD: - res = res.replace('\033', '\\033') return res diff --git a/esphomeyaml/mqtt.py b/esphomeyaml/mqtt.py index 5d67ab65e0..588a194d4e 100644 --- a/esphomeyaml/mqtt.py +++ b/esphomeyaml/mqtt.py @@ -74,8 +74,6 @@ def show_logs(config, topic=None, username=None, password=None, client_id=None): def on_message(client, userdata, msg): time = datetime.now().time().strftime(u'[%H:%M:%S]') message = time + msg.payload - if core.FROM_DASHBOARD: - message = message.replace('\033', '\\033') safe_print(message) return initialize(config, [topic], on_message, username, password, client_id) diff --git a/esphomeyaml/util.py b/esphomeyaml/util.py index 918bd8c2b0..3164061dec 100644 --- a/esphomeyaml/util.py +++ b/esphomeyaml/util.py @@ -55,7 +55,6 @@ class RedirectText(object): self._out = out def write(self, s): - s = s.replace('\033', '\\033') self._out.write(s) def flush(self): @@ -74,9 +73,8 @@ def run_external_command(func, *cmd, **kwargs): full_cmd = u' '.join(shlex_quote(x) for x in cmd) _LOGGER.info(u"Running: %s", full_cmd) - if core.FROM_DASHBOARD: - sys.stdout = RedirectText(sys.stdout) - sys.stderr = RedirectText(sys.stderr) + sys.stdout = RedirectText(sys.stdout) + sys.stderr = RedirectText(sys.stderr) capture_stdout = kwargs.get('capture_stdout', False) if capture_stdout: