created functional version with xset subprocess calls

This commit is contained in:
Mike Bloy 2021-03-08 08:42:01 -06:00
parent 0a29d2bad3
commit 519294c19a
2 changed files with 17 additions and 7 deletions

View File

@ -2,6 +2,7 @@
import asyncio
import logging
import subprocess
from contextlib import AsyncExitStack
from typing import Any, Dict, Set
@ -49,11 +50,19 @@ async def screen_state_mqtt_handler(messages):
"""Screen state handler, reacts on presence messages."""
log = logging.getLogger(__name__)
async for message in messages:
log.info(
"screen sate message on topic %s: %s",
message.topic,
message.payload.decode(),
)
payload = message.payload.decode()
log.info("screen sate message on topic %s: %s", message.topic, payload)
if payload == "on":
cmd = ["xset", "dpms", "force", "on"]
log.info("motion detected, forcing screen state to on. CMD: %s", cmd)
result = subprocess.run(cmd, capture_output=True)
if result.returncode != 0:
log.error(
"nonzero return code: %s. stderr: %r, stdout: %r",
result.returncode,
result.stderr,
result.stdout,
)
async def cancel_tasks(tasks):

View File

@ -1,5 +1,5 @@
[tox]
envlist = py37,security,lint,bundle
envlist = py37,security,lint
isolated_build = True
[testenv]
@ -14,6 +14,7 @@ deps = setuptools
deps =
importlib_metadata
pytest
pytest-asyncio
pytest-cov
pdbpp
commands =
@ -29,7 +30,7 @@ commands =
deps =
bandit
commands =
bandit {envsitepackagesdir}/hasskiosk -r
bandit {toxinidir}/src/hasskiosk -r
[testenv:lint]
deps =