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 asyncio
import logging import logging
import subprocess
from contextlib import AsyncExitStack from contextlib import AsyncExitStack
from typing import Any, Dict, Set from typing import Any, Dict, Set
@ -49,10 +50,18 @@ async def screen_state_mqtt_handler(messages):
"""Screen state handler, reacts on presence messages.""" """Screen state handler, reacts on presence messages."""
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
async for message in messages: async for message in messages:
log.info( payload = message.payload.decode()
"screen sate message on topic %s: %s", log.info("screen sate message on topic %s: %s", message.topic, payload)
message.topic, if payload == "on":
message.payload.decode(), 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,
) )

View File

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