mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-09 10:59:43 +00:00
* Add API for swap configuration Add HTTP API for swap size and swappiness to /os/config/swap. Individual options can be set in JSON and are calling the DBus API added in OS Agent 1.7.x, available since OS 15.0. Check for presence of OS of the required version and return 404 if the criteria are not met. * Fix type hints and reboot_required logic Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Fix formatting after adding suggestions from GH * Address @mdegat01 review comments - Improve swap options validation - Add swap to the 'all' property of dbus agent - Use APINotFound with reason instead of HTTPNotFound - Reorder API routes --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
43 lines
995 B
Python
43 lines
995 B
Python
"""Mock of OS Agent Swap dbus service."""
|
|
|
|
from dbus_fast.service import dbus_property
|
|
|
|
from .base import DBusServiceMock
|
|
|
|
BUS_NAME = "io.hass.os"
|
|
|
|
|
|
def setup(object_path: str | None = None) -> DBusServiceMock:
|
|
"""Create dbus mock object."""
|
|
return Swap()
|
|
|
|
|
|
class Swap(DBusServiceMock):
|
|
"""Swap mock.
|
|
|
|
gdbus introspect --system --dest io.hass.os --object-path /io/hass/os/Config/Swap
|
|
"""
|
|
|
|
object_path = "/io/hass/os/Config/Swap"
|
|
interface = "io.hass.os.Config.Swap"
|
|
|
|
@dbus_property()
|
|
def SwapSize(self) -> "s":
|
|
"""Get swap size."""
|
|
return "1M"
|
|
|
|
@SwapSize.setter
|
|
def SwapSize(self, value: "s"):
|
|
"""Set swap size."""
|
|
self.emit_properties_changed({"SwapSize": value})
|
|
|
|
@dbus_property()
|
|
def Swappiness(self) -> "i":
|
|
"""Get swappiness."""
|
|
return 1
|
|
|
|
@Swappiness.setter
|
|
def Swappiness(self, value: "i"):
|
|
"""Set swappiness."""
|
|
self.emit_properties_changed({"Swappiness": value})
|