Expose web_server port via the API (#2467)

This commit is contained in:
Alex Iribarren 2021-10-28 00:46:55 +02:00 committed by GitHub
parent b3d7cc637b
commit 0d3e6b2c4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View File

@ -10,6 +10,7 @@ from esphome.const import (
CONF_USE_ADDRESS, CONF_USE_ADDRESS,
CONF_ETHERNET, CONF_ETHERNET,
CONF_WIFI, CONF_WIFI,
CONF_PORT,
KEY_CORE, KEY_CORE,
KEY_TARGET_FRAMEWORK, KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM, KEY_TARGET_PLATFORM,
@ -519,6 +520,19 @@ class EsphomeCore:
return None return None
@property
def web_port(self) -> Optional[int]:
if self.config is None:
raise ValueError("Config has not been loaded yet")
if "web_server" in self.config:
try:
return self.config["web_server"][CONF_PORT]
except KeyError:
return 80
return None
@property @property
def comment(self) -> Optional[str]: def comment(self) -> Optional[str]:
if self.config is None: if self.config is None:

View File

@ -509,6 +509,12 @@ class DashboardEntry:
return None return None
return self.storage.address return self.storage.address
@property
def web_port(self):
if self.storage is None:
return None
return self.storage.web_port
@property @property
def name(self): def name(self):
if self.storage is None: if self.storage is None:
@ -569,6 +575,7 @@ class ListDevicesHandler(BaseHandler):
"path": entry.path, "path": entry.path,
"comment": entry.comment, "comment": entry.comment,
"address": entry.address, "address": entry.address,
"web_port": entry.web_port,
"target_platform": entry.target_platform, "target_platform": entry.target_platform,
} }
for entry in entries for entry in entries

View File

@ -41,6 +41,7 @@ class StorageJSON:
esphome_version, esphome_version,
src_version, src_version,
address, address,
web_port,
target_platform, target_platform,
build_path, build_path,
firmware_bin_path, firmware_bin_path,
@ -60,6 +61,9 @@ class StorageJSON:
self.src_version = src_version # type: int self.src_version = src_version # type: int
# Address of the ESP, for example livingroom.local or a static IP # Address of the ESP, for example livingroom.local or a static IP
self.address = address # type: str self.address = address # type: str
# Web server port of the ESP, for example 80
assert web_port is None or isinstance(web_port, int)
self.web_port = web_port # type: int
# The type of ESP in use, either ESP32 or ESP8266 # The type of ESP in use, either ESP32 or ESP8266
self.target_platform = target_platform # type: str self.target_platform = target_platform # type: str
# The absolute path to the platformio project # The absolute path to the platformio project
@ -78,6 +82,7 @@ class StorageJSON:
"esphome_version": self.esphome_version, "esphome_version": self.esphome_version,
"src_version": self.src_version, "src_version": self.src_version,
"address": self.address, "address": self.address,
"web_port": self.web_port,
"esp_platform": self.target_platform, "esp_platform": self.target_platform,
"build_path": self.build_path, "build_path": self.build_path,
"firmware_bin_path": self.firmware_bin_path, "firmware_bin_path": self.firmware_bin_path,
@ -101,6 +106,7 @@ class StorageJSON:
esphome_version=const.__version__, esphome_version=const.__version__,
src_version=1, src_version=1,
address=esph.address, address=esph.address,
web_port=esph.web_port,
target_platform=esph.target_platform, target_platform=esph.target_platform,
build_path=esph.build_path, build_path=esph.build_path,
firmware_bin_path=esph.firmware_bin, firmware_bin_path=esph.firmware_bin,
@ -117,6 +123,7 @@ class StorageJSON:
esphome_version=const.__version__, esphome_version=const.__version__,
src_version=1, src_version=1,
address=address, address=address,
web_port=None,
target_platform=esp_platform, target_platform=esp_platform,
build_path=None, build_path=None,
firmware_bin_path=None, firmware_bin_path=None,
@ -135,6 +142,7 @@ class StorageJSON:
) )
src_version = storage.get("src_version") src_version = storage.get("src_version")
address = storage.get("address") address = storage.get("address")
web_port = storage.get("web_port")
esp_platform = storage.get("esp_platform") esp_platform = storage.get("esp_platform")
build_path = storage.get("build_path") build_path = storage.get("build_path")
firmware_bin_path = storage.get("firmware_bin_path") firmware_bin_path = storage.get("firmware_bin_path")
@ -146,6 +154,7 @@ class StorageJSON:
esphome_version, esphome_version,
src_version, src_version,
address, address,
web_port,
esp_platform, esp_platform,
build_path, build_path,
firmware_bin_path, firmware_bin_path,