mirror of
https://github.com/home-assistant/core
synced 2024-07-30 21:18:57 +02:00
Add a new clear cache service to the velbus integration (#79995)
This commit is contained in:
parent
e18adb379d
commit
33ef2abf9e
@ -1,7 +1,9 @@
|
|||||||
"""Support for Velbus devices."""
|
"""Support for Velbus devices."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from contextlib import suppress
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from velbusaio.controller import Velbus
|
from velbusaio.controller import Velbus
|
||||||
@ -19,6 +21,7 @@ from .const import (
|
|||||||
CONF_INTERFACE,
|
CONF_INTERFACE,
|
||||||
CONF_MEMO_TEXT,
|
CONF_MEMO_TEXT,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
SERVICE_CLEAR_CACHE,
|
||||||
SERVICE_SCAN,
|
SERVICE_SCAN,
|
||||||
SERVICE_SET_MEMO_TEXT,
|
SERVICE_SET_MEMO_TEXT,
|
||||||
SERVICE_SYNC,
|
SERVICE_SYNC,
|
||||||
@ -132,6 +135,42 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def clear_cache(call: ServiceCall) -> None:
|
||||||
|
"""Handle a clear cache service call."""
|
||||||
|
# clear the cache
|
||||||
|
with suppress(FileNotFoundError):
|
||||||
|
if call.data[CONF_ADDRESS]:
|
||||||
|
await hass.async_add_executor_job(
|
||||||
|
os.unlink,
|
||||||
|
hass.config.path(
|
||||||
|
STORAGE_DIR,
|
||||||
|
f"velbuscache-{call.data[CONF_INTERFACE]}/{call.data[CONF_ADDRESS]}.p",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await hass.async_add_executor_job(
|
||||||
|
shutil.rmtree,
|
||||||
|
hass.config.path(
|
||||||
|
STORAGE_DIR, f"velbuscache-{call.data[CONF_INTERFACE]}/"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
# call a scan to repopulate
|
||||||
|
await scan(call)
|
||||||
|
|
||||||
|
hass.services.async_register(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_CLEAR_CACHE,
|
||||||
|
clear_cache,
|
||||||
|
vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required(CONF_INTERFACE): vol.All(cv.string, check_entry_id),
|
||||||
|
vol.Optional(CONF_ADDRESS): vol.All(
|
||||||
|
vol.Coerce(int), vol.Range(min=0, max=255)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -149,4 +188,5 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.services.async_remove(DOMAIN, SERVICE_SCAN)
|
hass.services.async_remove(DOMAIN, SERVICE_SCAN)
|
||||||
hass.services.async_remove(DOMAIN, SERVICE_SYNC)
|
hass.services.async_remove(DOMAIN, SERVICE_SYNC)
|
||||||
hass.services.async_remove(DOMAIN, SERVICE_SET_MEMO_TEXT)
|
hass.services.async_remove(DOMAIN, SERVICE_SET_MEMO_TEXT)
|
||||||
|
hass.services.async_remove(DOMAIN, SERVICE_CLEAR_CACHE)
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
@ -16,6 +16,7 @@ CONF_MEMO_TEXT: Final = "memo_text"
|
|||||||
SERVICE_SCAN: Final = "scan"
|
SERVICE_SCAN: Final = "scan"
|
||||||
SERVICE_SYNC: Final = "sync_clock"
|
SERVICE_SYNC: Final = "sync_clock"
|
||||||
SERVICE_SET_MEMO_TEXT: Final = "set_memo_text"
|
SERVICE_SET_MEMO_TEXT: Final = "set_memo_text"
|
||||||
|
SERVICE_CLEAR_CACHE: Final = "clear_cache"
|
||||||
|
|
||||||
PRESET_MODES: Final = {
|
PRESET_MODES: Final = {
|
||||||
PRESET_ECO: "safe",
|
PRESET_ECO: "safe",
|
||||||
|
@ -24,6 +24,29 @@ scan:
|
|||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
|
|
||||||
|
clear_cache:
|
||||||
|
name: Clear cache
|
||||||
|
description: Clears the velbuscache and then starts a new scan
|
||||||
|
fields:
|
||||||
|
interface:
|
||||||
|
name: Interface
|
||||||
|
description: The velbus interface to send the command to, this will be the same value as used during configuration
|
||||||
|
required: true
|
||||||
|
example: "192.168.1.5:27015"
|
||||||
|
default: ""
|
||||||
|
selector:
|
||||||
|
text:
|
||||||
|
address:
|
||||||
|
name: Address
|
||||||
|
description: >
|
||||||
|
The module address in decimal format, if this is provided we only clear this module, if nothing is provided we clear the whole cache directory (all modules)
|
||||||
|
The decimal addresses are displayed in front of the modules listed at the integration page.
|
||||||
|
required: false
|
||||||
|
selector:
|
||||||
|
number:
|
||||||
|
min: 1
|
||||||
|
max: 254
|
||||||
|
|
||||||
set_memo_text:
|
set_memo_text:
|
||||||
name: Set memo text
|
name: Set memo text
|
||||||
description: >
|
description: >
|
||||||
|
Loading…
Reference in New Issue
Block a user