-
Notifications
You must be signed in to change notification settings - Fork 0
/
slavepower.py
executable file
·32 lines (24 loc) · 969 Bytes
/
slavepower.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# SlavePower synch the power status of a slave device to a master's power status
#
# Copyright (C) 2024 Andre Malenfant ([email protected])
#
# This file may be distributed under the terms of the GNU GPLv3 license.
from __future__ import annotations
import logging
from typing import (
Dict,
Any,
)
class SlavePower:
def __init__(self, config):
self.server = config.get_server()
self.name = config.get_name()
self.master = config.get("master")
self.slave = config.get("slave")
self.server.register_event_handler("power:power_changed", self._on_power_changed)
def _on_power_changed(self, device_info: Dict[str, Any]) -> None:
if device_info["device"] == self.master:
power: PrinterPower = self.server.lookup_component("power")
power.set_device_power(self.slave, device_info["status"])
def load_component(config):
return SlavePower(config)