mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-31 18:11:54 +08:00
refactoring
This commit is contained in:
@@ -172,7 +172,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
|
||||
|
||||
self.__snapshot: Optional[StreamerSnapshot] = None
|
||||
|
||||
self.__state_notifier = aiotools.AioNotifier()
|
||||
self.__notifier = aiotools.AioNotifier()
|
||||
|
||||
# =====
|
||||
|
||||
@@ -277,7 +277,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
|
||||
async def poll_state(self) -> AsyncGenerator[Dict, None]:
|
||||
def signal_handler(*_: Any) -> None:
|
||||
get_logger(0).info("Got SIGUSR2, checking the stream state ...")
|
||||
asyncio.ensure_future(self.__state_notifier.notify())
|
||||
asyncio.ensure_future(self.__notifier.notify())
|
||||
|
||||
get_logger(0).info("Installing SIGUSR2 streamer handler ...")
|
||||
asyncio.get_event_loop().add_signal_handler(signal.SIGUSR2, signal_handler)
|
||||
@@ -291,7 +291,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
|
||||
prev_state = state
|
||||
|
||||
if waiter_task is None:
|
||||
waiter_task = asyncio.create_task(self.__state_notifier.wait())
|
||||
waiter_task = asyncio.create_task(self.__notifier.wait())
|
||||
if waiter_task in (await aiotools.wait_first(asyncio.sleep(self.__state_poll), waiter_task))[0]:
|
||||
waiter_task = None
|
||||
|
||||
@@ -328,7 +328,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
|
||||
)
|
||||
if save:
|
||||
self.__snapshot = snapshot
|
||||
await self.__state_notifier.notify()
|
||||
await self.__notifier.notify()
|
||||
return snapshot
|
||||
logger.error("Stream is offline, no signal or so")
|
||||
except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError) as err:
|
||||
|
||||
@@ -215,12 +215,12 @@ class UserGpio:
|
||||
def __init__(self, config: Section) -> None:
|
||||
self.__view = config.view
|
||||
|
||||
self.__state_notifier = aiotools.AioNotifier()
|
||||
self.__notifier = aiotools.AioNotifier()
|
||||
|
||||
self.__drivers = {
|
||||
driver: get_ugpio_driver_class(drv_config.type)(
|
||||
instance_name=driver,
|
||||
notifier=self.__state_notifier,
|
||||
notifier=self.__notifier,
|
||||
**drv_config._unpack(ignore=["instance_name", "notifier", "type"]),
|
||||
)
|
||||
for (driver, drv_config) in config.drivers.items()
|
||||
@@ -236,7 +236,7 @@ class UserGpio:
|
||||
if ch_config.mode == "input":
|
||||
self.__inputs[channel] = _GpioInput(channel, ch_config, driver)
|
||||
else: # output:
|
||||
self.__outputs[channel] = _GpioOutput(channel, ch_config, driver, self.__state_notifier)
|
||||
self.__outputs[channel] = _GpioOutput(channel, ch_config, driver, self.__notifier)
|
||||
|
||||
async def get_model(self) -> Dict:
|
||||
return {
|
||||
@@ -260,7 +260,7 @@ class UserGpio:
|
||||
if state != prev_state:
|
||||
yield state
|
||||
prev_state = state
|
||||
await self.__state_notifier.wait()
|
||||
await self.__notifier.wait()
|
||||
|
||||
def sysprep(self) -> None:
|
||||
get_logger().info("Preparing User-GPIO drivers ...")
|
||||
|
||||
Reference in New Issue
Block a user