mirror of
https://github.com/esphome/esphome.git
synced 2025-09-03 03:42:20 +01:00
Bump python min to 3.9 (#3871)
This commit is contained in:
@@ -4,7 +4,7 @@ from datetime import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from typing import Any, Optional, List
|
||||
from typing import Optional
|
||||
|
||||
from esphome import const
|
||||
from esphome.core import CORE
|
||||
@@ -15,19 +15,19 @@ from esphome.types import CoreType
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def storage_path(): # type: () -> str
|
||||
def storage_path() -> str:
|
||||
return CORE.relative_internal_path(f"{CORE.config_filename}.json")
|
||||
|
||||
|
||||
def ext_storage_path(base_path, config_filename): # type: (str, str) -> str
|
||||
def ext_storage_path(base_path: str, config_filename: str) -> str:
|
||||
return os.path.join(base_path, ".esphome", f"{config_filename}.json")
|
||||
|
||||
|
||||
def esphome_storage_path(base_path): # type: (str) -> str
|
||||
def esphome_storage_path(base_path: str) -> str:
|
||||
return os.path.join(base_path, ".esphome", "esphome.json")
|
||||
|
||||
|
||||
def trash_storage_path(base_path): # type: (str) -> str
|
||||
def trash_storage_path(base_path: str) -> str:
|
||||
return os.path.join(base_path, ".esphome", "trash")
|
||||
|
||||
|
||||
@@ -49,29 +49,29 @@ class StorageJSON:
|
||||
):
|
||||
# Version of the storage JSON schema
|
||||
assert storage_version is None or isinstance(storage_version, int)
|
||||
self.storage_version = storage_version # type: int
|
||||
self.storage_version: int = storage_version
|
||||
# The name of the node
|
||||
self.name = name # type: str
|
||||
self.name: str = name
|
||||
# The comment of the node
|
||||
self.comment = comment # type: str
|
||||
self.comment: str = comment
|
||||
# The esphome version this was compiled with
|
||||
self.esphome_version = esphome_version # type: str
|
||||
self.esphome_version: str = esphome_version
|
||||
# The version of the file in src/main.cpp - Used to migrate the file
|
||||
assert src_version is None or isinstance(src_version, int)
|
||||
self.src_version = src_version # type: int
|
||||
self.src_version: int = src_version
|
||||
# Address of the ESP, for example livingroom.local or a static IP
|
||||
self.address = address # type: str
|
||||
self.address: str = address
|
||||
# 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
|
||||
self.web_port: int = web_port
|
||||
# The type of hardware in use, like "ESP32", "ESP32C3", "ESP8266", etc.
|
||||
self.target_platform = target_platform # type: str
|
||||
self.target_platform: str = target_platform
|
||||
# The absolute path to the platformio project
|
||||
self.build_path = build_path # type: str
|
||||
self.build_path: str = build_path
|
||||
# The absolute path to the firmware binary
|
||||
self.firmware_bin_path = firmware_bin_path # type: str
|
||||
self.firmware_bin_path: str = firmware_bin_path
|
||||
# A list of strings of names of loaded integrations
|
||||
self.loaded_integrations = loaded_integrations # type: List[str]
|
||||
self.loaded_integrations: list[str] = loaded_integrations
|
||||
self.loaded_integrations.sort()
|
||||
|
||||
def as_dict(self):
|
||||
@@ -97,8 +97,8 @@ class StorageJSON:
|
||||
|
||||
@staticmethod
|
||||
def from_esphome_core(
|
||||
esph, old
|
||||
): # type: (CoreType, Optional[StorageJSON]) -> StorageJSON
|
||||
esph: CoreType, old: Optional["StorageJSON"]
|
||||
) -> "StorageJSON":
|
||||
hardware = esph.target_platform.upper()
|
||||
if esph.is_esp32:
|
||||
from esphome.components import esp32
|
||||
@@ -135,7 +135,7 @@ class StorageJSON:
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _load_impl(path): # type: (str) -> Optional[StorageJSON]
|
||||
def _load_impl(path: str) -> Optional["StorageJSON"]:
|
||||
with codecs.open(path, "r", encoding="utf-8") as f_handle:
|
||||
storage = json.load(f_handle)
|
||||
storage_version = storage["storage_version"]
|
||||
@@ -166,13 +166,13 @@ class StorageJSON:
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def load(path): # type: (str) -> Optional[StorageJSON]
|
||||
def load(path: str) -> Optional["StorageJSON"]:
|
||||
try:
|
||||
return StorageJSON._load_impl(path)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return None
|
||||
|
||||
def __eq__(self, o): # type: (Any) -> bool
|
||||
def __eq__(self, o) -> bool:
|
||||
return isinstance(o, StorageJSON) and self.as_dict() == o.as_dict()
|
||||
|
||||
|
||||
@@ -182,15 +182,15 @@ class EsphomeStorageJSON:
|
||||
):
|
||||
# Version of the storage JSON schema
|
||||
assert storage_version is None or isinstance(storage_version, int)
|
||||
self.storage_version = storage_version # type: int
|
||||
self.storage_version: int = storage_version
|
||||
# The cookie secret for the dashboard
|
||||
self.cookie_secret = cookie_secret # type: str
|
||||
self.cookie_secret: str = cookie_secret
|
||||
# The last time ESPHome checked for an update as an isoformat encoded str
|
||||
self.last_update_check_str = last_update_check # type: str
|
||||
self.last_update_check_str: str = last_update_check
|
||||
# Cache of the version gotten in the last version check
|
||||
self.remote_version = remote_version # type: Optional[str]
|
||||
self.remote_version: Optional[str] = remote_version
|
||||
|
||||
def as_dict(self): # type: () -> dict
|
||||
def as_dict(self) -> dict:
|
||||
return {
|
||||
"storage_version": self.storage_version,
|
||||
"cookie_secret": self.cookie_secret,
|
||||
@@ -199,24 +199,24 @@ class EsphomeStorageJSON:
|
||||
}
|
||||
|
||||
@property
|
||||
def last_update_check(self): # type: () -> Optional[datetime]
|
||||
def last_update_check(self) -> Optional[datetime]:
|
||||
try:
|
||||
return datetime.strptime(self.last_update_check_str, "%Y-%m-%dT%H:%M:%S")
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return None
|
||||
|
||||
@last_update_check.setter
|
||||
def last_update_check(self, new): # type: (datetime) -> None
|
||||
def last_update_check(self, new: datetime) -> None:
|
||||
self.last_update_check_str = new.strftime("%Y-%m-%dT%H:%M:%S")
|
||||
|
||||
def to_json(self): # type: () -> dict
|
||||
def to_json(self) -> dict:
|
||||
return f"{json.dumps(self.as_dict(), indent=2)}\n"
|
||||
|
||||
def save(self, path): # type: (str) -> None
|
||||
def save(self, path: str) -> None:
|
||||
write_file_if_changed(path, self.to_json())
|
||||
|
||||
@staticmethod
|
||||
def _load_impl(path): # type: (str) -> Optional[EsphomeStorageJSON]
|
||||
def _load_impl(path: str) -> Optional["EsphomeStorageJSON"]:
|
||||
with codecs.open(path, "r", encoding="utf-8") as f_handle:
|
||||
storage = json.load(f_handle)
|
||||
storage_version = storage["storage_version"]
|
||||
@@ -228,14 +228,14 @@ class EsphomeStorageJSON:
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def load(path): # type: (str) -> Optional[EsphomeStorageJSON]
|
||||
def load(path: str) -> Optional["EsphomeStorageJSON"]:
|
||||
try:
|
||||
return EsphomeStorageJSON._load_impl(path)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_default(): # type: () -> EsphomeStorageJSON
|
||||
def get_default() -> "EsphomeStorageJSON":
|
||||
return EsphomeStorageJSON(
|
||||
storage_version=1,
|
||||
cookie_secret=binascii.hexlify(os.urandom(64)).decode(),
|
||||
@@ -243,5 +243,5 @@ class EsphomeStorageJSON:
|
||||
remote_version=None,
|
||||
)
|
||||
|
||||
def __eq__(self, o): # type: (Any) -> bool
|
||||
def __eq__(self, o) -> bool:
|
||||
return isinstance(o, EsphomeStorageJSON) and self.as_dict() == o.as_dict()
|
||||
|
Reference in New Issue
Block a user