Restore KNX telegram history (#95800)
* Restore KNX telegram history * increase default log size * test removal of telegram history
This commit is contained in:
parent
8bbb395bec
commit
89259865fb
6 changed files with 163 additions and 17 deletions
|
@ -74,7 +74,7 @@ from .const import (
|
|||
)
|
||||
from .device import KNXInterfaceDevice
|
||||
from .expose import KNXExposeSensor, KNXExposeTime, create_knx_exposure
|
||||
from .project import KNXProject
|
||||
from .project import STORAGE_KEY as PROJECT_STORAGE_KEY, KNXProject
|
||||
from .schema import (
|
||||
BinarySensorSchema,
|
||||
ButtonSchema,
|
||||
|
@ -96,7 +96,7 @@ from .schema import (
|
|||
ga_validator,
|
||||
sensor_type_validator,
|
||||
)
|
||||
from .telegrams import Telegrams
|
||||
from .telegrams import STORAGE_KEY as TELEGRAMS_STORAGE_KEY, Telegrams
|
||||
from .websocket import register_panel
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -360,16 +360,21 @@ async def async_update_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||
async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
"""Remove a config entry."""
|
||||
|
||||
def remove_keyring_files(file_path: Path) -> None:
|
||||
"""Remove keyring files."""
|
||||
def remove_files(storage_dir: Path, knxkeys_filename: str | None) -> None:
|
||||
"""Remove KNX files."""
|
||||
if knxkeys_filename is not None:
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
(storage_dir / knxkeys_filename).unlink()
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
file_path.unlink()
|
||||
(storage_dir / PROJECT_STORAGE_KEY).unlink()
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
(storage_dir / TELEGRAMS_STORAGE_KEY).unlink()
|
||||
with contextlib.suppress(FileNotFoundError, OSError):
|
||||
file_path.parent.rmdir()
|
||||
(storage_dir / DOMAIN).rmdir()
|
||||
|
||||
if (_knxkeys_file := entry.data.get(CONF_KNX_KNXKEY_FILENAME)) is not None:
|
||||
file_path = Path(hass.config.path(STORAGE_DIR)) / _knxkeys_file
|
||||
await hass.async_add_executor_job(remove_keyring_files, file_path)
|
||||
storage_dir = Path(hass.config.path(STORAGE_DIR))
|
||||
knxkeys_filename = entry.data.get(CONF_KNX_KNXKEY_FILENAME)
|
||||
await hass.async_add_executor_job(remove_files, storage_dir, knxkeys_filename)
|
||||
|
||||
|
||||
class KNXModule:
|
||||
|
@ -420,11 +425,13 @@ class KNXModule:
|
|||
async def start(self) -> None:
|
||||
"""Start XKNX object. Connect to tunneling or Routing device."""
|
||||
await self.project.load_project()
|
||||
await self.telegrams.load_history()
|
||||
await self.xknx.start()
|
||||
|
||||
async def stop(self, event: Event | None = None) -> None:
|
||||
"""Stop XKNX object. Disconnect from tunneling or Routing device."""
|
||||
await self.xknx.stop()
|
||||
await self.telegrams.save_history()
|
||||
|
||||
def connection_config(self) -> ConnectionConfig:
|
||||
"""Return the connection_config."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue