mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Check permissions (#6255)
This commit is contained in:
parent
6a8a2aaefb
commit
9c95e570c7
1 changed files with 20 additions and 0 deletions
|
@ -297,8 +297,27 @@ def upload_using_platformio(config, port):
|
||||||
return platformio_api.run_platformio_cli_run(config, CORE.verbose, *upload_args)
|
return platformio_api.run_platformio_cli_run(config, CORE.verbose, *upload_args)
|
||||||
|
|
||||||
|
|
||||||
|
def check_permissions(port):
|
||||||
|
if os.name == "posix" and get_port_type(port) == "SERIAL":
|
||||||
|
# Check if we can open selected serial port
|
||||||
|
if not os.access(port, os.F_OK):
|
||||||
|
raise EsphomeError(
|
||||||
|
"The selected serial port does not exist. To resolve this issue, "
|
||||||
|
"check that the device is connected to this computer with a USB cable and that "
|
||||||
|
"the USB cable can be used for data and is not a power-only cable."
|
||||||
|
)
|
||||||
|
if not (os.access(port, os.R_OK | os.W_OK)):
|
||||||
|
raise EsphomeError(
|
||||||
|
"You do not have read or write permission on the selected serial port. "
|
||||||
|
"To resolve this issue, you can add your user to the dialout group "
|
||||||
|
f"by running the following command: sudo usermod -a -G dialout {os.getlogin()}. "
|
||||||
|
"You will need to log out & back in or reboot to activate the new group access."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def upload_program(config, args, host):
|
def upload_program(config, args, host):
|
||||||
if get_port_type(host) == "SERIAL":
|
if get_port_type(host) == "SERIAL":
|
||||||
|
check_permissions(host)
|
||||||
if CORE.target_platform in (PLATFORM_ESP32, PLATFORM_ESP8266):
|
if CORE.target_platform in (PLATFORM_ESP32, PLATFORM_ESP8266):
|
||||||
file = getattr(args, "file", None)
|
file = getattr(args, "file", None)
|
||||||
return upload_using_esptool(config, host, file)
|
return upload_using_esptool(config, host, file)
|
||||||
|
@ -344,6 +363,7 @@ def show_logs(config, args, port):
|
||||||
if "logger" not in config:
|
if "logger" not in config:
|
||||||
raise EsphomeError("Logger is not configured!")
|
raise EsphomeError("Logger is not configured!")
|
||||||
if get_port_type(port) == "SERIAL":
|
if get_port_type(port) == "SERIAL":
|
||||||
|
check_permissions(port)
|
||||||
return run_miniterm(config, port)
|
return run_miniterm(config, port)
|
||||||
if get_port_type(port) == "NETWORK" and "api" in config:
|
if get_port_type(port) == "NETWORK" and "api" in config:
|
||||||
if config[CONF_MDNS][CONF_DISABLED] and CONF_MQTT in config:
|
if config[CONF_MDNS][CONF_DISABLED] and CONF_MQTT in config:
|
||||||
|
|
Loading…
Reference in a new issue