mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
tesmart: check channel after switching
This commit is contained in:
parent
ee99d3545c
commit
61acd1c5e4
@ -112,10 +112,17 @@ class AioNotifier:
|
|||||||
def notify_sync(self) -> None:
|
def notify_sync(self) -> None:
|
||||||
self.__queue.put_nowait(None)
|
self.__queue.put_nowait(None)
|
||||||
|
|
||||||
async def wait(self) -> None:
|
async def wait(self, timeout: Optional[float]=None) -> None:
|
||||||
await self.__queue.get()
|
if timeout is None:
|
||||||
|
await self.__queue.get()
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
await asyncio.wait_for(self.__queue.get(), timeout=timeout)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
return # False
|
||||||
while not self.__queue.empty():
|
while not self.__queue.empty():
|
||||||
await self.__queue.get()
|
await self.__queue.get()
|
||||||
|
# return True
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|||||||
@ -52,7 +52,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
host: str,
|
host: str,
|
||||||
port: int,
|
port: int,
|
||||||
timeout: float,
|
timeout: float,
|
||||||
send_delay: float,
|
switch_delay: float,
|
||||||
state_poll: float,
|
state_poll: float,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
@ -61,22 +61,22 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
self.__host = host
|
self.__host = host
|
||||||
self.__port = port
|
self.__port = port
|
||||||
self.__timeout = timeout
|
self.__timeout = timeout
|
||||||
self.__send_delay = send_delay
|
self.__switch_delay = switch_delay
|
||||||
self.__state_poll = state_poll
|
self.__state_poll = state_poll
|
||||||
|
|
||||||
self.__reader: Optional[asyncio.StreamReader] = None
|
self.__reader: Optional[asyncio.StreamReader] = None
|
||||||
self.__writer: Optional[asyncio.StreamWriter] = None
|
self.__writer: Optional[asyncio.StreamWriter] = None
|
||||||
|
|
||||||
self.__active: int = -1
|
self.__active: int = -1
|
||||||
|
self.__update_notifier = aiotools.AioNotifier()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_plugin_options(cls) -> Dict:
|
def get_plugin_options(cls) -> Dict:
|
||||||
return {
|
return {
|
||||||
"host": Option("", type=valid_ip_or_host),
|
"host": Option("", type=valid_ip_or_host),
|
||||||
"port": Option(5000, type=valid_port),
|
"port": Option(5000, type=valid_port),
|
||||||
"timeout": Option(5.0, type=valid_float_f01),
|
"timeout": Option(5.0, type=valid_float_f01),
|
||||||
"send_delay": Option(1.0, type=valid_float_f0),
|
"switch_delay": Option(1.0, type=valid_float_f0),
|
||||||
"state_poll": Option(5.0, type=valid_float_f01),
|
"state_poll": Option(5.0, type=valid_float_f01),
|
||||||
}
|
}
|
||||||
|
|
||||||
def register_input(self, pin: int, debounce: float) -> None:
|
def register_input(self, pin: int, debounce: float) -> None:
|
||||||
@ -95,6 +95,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
prev_active = -2
|
prev_active = -2
|
||||||
while True:
|
while True:
|
||||||
|
await self.__update_notifier.wait(self.__state_poll)
|
||||||
try:
|
try:
|
||||||
self.__active = await self.__send_command(b"\x10\x00")
|
self.__active = await self.__send_command(b"\x10\x00")
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -102,7 +103,6 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
if self.__active != prev_active:
|
if self.__active != prev_active:
|
||||||
await self._notifier.notify()
|
await self._notifier.notify()
|
||||||
prev_active = self.__active
|
prev_active = self.__active
|
||||||
await asyncio.sleep(self.__state_poll)
|
|
||||||
|
|
||||||
async def cleanup(self) -> None:
|
async def cleanup(self) -> None:
|
||||||
await self.__close_device()
|
await self.__close_device()
|
||||||
@ -113,7 +113,8 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
async def write(self, pin: int, state: bool) -> None:
|
async def write(self, pin: int, state: bool) -> None:
|
||||||
if state:
|
if state:
|
||||||
await self.__send_command(b"\x01%.2x" % (pin - 1))
|
await self.__send_command(b"\x01%.2x" % (pin - 1))
|
||||||
await asyncio.sleep(self.__send_delay) # Slowdown
|
await self.__update_notifier.notify()
|
||||||
|
await asyncio.sleep(self.__switch_delay) # Slowdown
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user