Integrate with CEC
This commit is contained in:
parent
fcfe97ad89
commit
597a10543d
10
microkodi/cec_handler.py
Normal file
10
microkodi/cec_handler.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import cec
|
||||||
|
|
||||||
|
class CECHandler:
|
||||||
|
def __init__(self):
|
||||||
|
cec.init()
|
||||||
|
|
||||||
|
def power_on_if_needed(self):
|
||||||
|
tc = cec.Device(cec.CECDEVICE_TV)
|
||||||
|
if not tc.is_on():
|
||||||
|
tc.power_on()
|
@ -38,6 +38,9 @@ class Config:
|
|||||||
# The entire configuration file for use in user scripts
|
# The entire configuration file for use in user scripts
|
||||||
options: dict[str, Any]
|
options: dict[str, Any]
|
||||||
|
|
||||||
|
# Enables the use of CEC
|
||||||
|
cec: bool
|
||||||
|
|
||||||
def load_config(config_path: Path | None) -> Config:
|
def load_config(config_path: Path | None) -> Config:
|
||||||
if config_path is None:
|
if config_path is None:
|
||||||
config_data = {}
|
config_data = {}
|
||||||
@ -64,4 +67,5 @@ def load_config(config_path: Path | None) -> Config:
|
|||||||
config_data.get("players", {}),
|
config_data.get("players", {}),
|
||||||
),
|
),
|
||||||
options=config_data.get("options", {}),
|
options=config_data.get("options", {}),
|
||||||
|
cec=config_data.get("cec", False),
|
||||||
)
|
)
|
||||||
|
@ -151,6 +151,11 @@ class PlayerRpcObject(JsonRpcObject):
|
|||||||
|
|
||||||
@after(lambda: I.get("DataBridge").set_loading(False))
|
@after(lambda: I.get("DataBridge").set_loading(False))
|
||||||
def open(self, params: dict[str, Any]) -> Any:
|
def open(self, params: dict[str, Any]) -> Any:
|
||||||
|
# Turn on the TV
|
||||||
|
config: Config = I.get("Config")
|
||||||
|
if config.cec:
|
||||||
|
I.get("CECHandler").power_on_if_needed()
|
||||||
|
|
||||||
I.get("DataBridge").set_loading(True)
|
I.get("DataBridge").set_loading(True)
|
||||||
url = urlparse(params["item"]["file"])
|
url = urlparse(params["item"]["file"])
|
||||||
|
|
||||||
@ -161,7 +166,6 @@ class PlayerRpcObject(JsonRpcObject):
|
|||||||
url = urlparse(url.query)
|
url = urlparse(url.query)
|
||||||
|
|
||||||
# Find out what player class to use
|
# Find out what player class to use
|
||||||
config: Config = I.get("Config")
|
|
||||||
scheme_configuration = config.players.get(url.scheme)
|
scheme_configuration = config.players.get(url.scheme)
|
||||||
if scheme_configuration is None:
|
if scheme_configuration is None:
|
||||||
I.get("DataBridge").notification.emit(f"No player available for {url.scheme}")
|
I.get("DataBridge").notification.emit(f"No player available for {url.scheme}")
|
||||||
|
@ -13,6 +13,7 @@ from PySide6.QtQml import QQmlApplicationEngine
|
|||||||
from microkodi.jsonrpc import JsonRpcHandler, GlobalMethodHandler
|
from microkodi.jsonrpc import JsonRpcHandler, GlobalMethodHandler
|
||||||
from microkodi.ui.bridge import DataBridge
|
from microkodi.ui.bridge import DataBridge
|
||||||
from microkodi.config import Config, load_config
|
from microkodi.config import Config, load_config
|
||||||
|
from microkodi.cec_handler import CECHandler
|
||||||
from microkodi.repository import I
|
from microkodi.repository import I
|
||||||
|
|
||||||
|
|
||||||
@ -23,6 +24,11 @@ def run_kodi_server():
|
|||||||
method_handler = GlobalMethodHandler()
|
method_handler = GlobalMethodHandler()
|
||||||
I.register("GlobalMethodHandler", method_handler)
|
I.register("GlobalMethodHandler", method_handler)
|
||||||
|
|
||||||
|
# Setup CEC
|
||||||
|
if config.cec:
|
||||||
|
I.register("CECHandler", CECHandler())
|
||||||
|
logger.info("Enabling CEC support")
|
||||||
|
|
||||||
# Load extra plugins
|
# Load extra plugins
|
||||||
if config.scripts:
|
if config.scripts:
|
||||||
logger.info("Loading scripts...")
|
logger.info("Loading scripts...")
|
||||||
|
@ -4,7 +4,8 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"pyside6",
|
"pyside6",
|
||||||
"requests",
|
"requests",
|
||||||
"yt-dlp"
|
"yt-dlp",
|
||||||
|
"cec"
|
||||||
]
|
]
|
||||||
|
|
||||||
[tools.build]
|
[tools.build]
|
||||||
|
Loading…
Reference in New Issue
Block a user