dim / switch off display when not used for 30 secs / 60 secs
parent
9fc2faf16c
commit
f96379afb0
|
@ -3,6 +3,7 @@
|
|||
import argparse
|
||||
import asyncio
|
||||
import coloredlogs
|
||||
import enum
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
@ -11,8 +12,14 @@ import time
|
|||
import ha_mqtt_discoverable
|
||||
import sensors
|
||||
|
||||
class BrightnessMode(enum.Enum):
|
||||
MODE_OFF = 0
|
||||
MODE_DIM = 1
|
||||
MODE_BRIGHT = 2
|
||||
|
||||
class InputListener():
|
||||
last_input = 0
|
||||
brightness_mode = BrightnessMode.MODE_OFF
|
||||
|
||||
def get_last_input(self):
|
||||
return self.last_input
|
||||
|
@ -30,6 +37,23 @@ class InputListener():
|
|||
|
||||
self.last_input = now
|
||||
|
||||
async def brightness_loop(self, logger):
|
||||
logger.info('starting brightess loop')
|
||||
while True:
|
||||
if self.last_input + 60 < time.time():
|
||||
if self.brightness_mode != BrightnessMode.MODE_OFF:
|
||||
await asyncio.create_subprocess_exec('brightnessctl', 'set', '0', stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL)
|
||||
self.brightness_mode = BrightnessMode.MODE_OFF
|
||||
elif self.last_input + 30 < time.time():
|
||||
if self.brightness_mode != BrightnessMode.MODE_DIM:
|
||||
await asyncio.create_subprocess_exec('brightnessctl', 'set', '5%', stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL)
|
||||
self.brightness_mode = BrightnessMode.MODE_DIM
|
||||
elif self.brightness_mode != BrightnessMode.MODE_BRIGHT:
|
||||
await asyncio.create_subprocess_exec('brightnessctl', 'set', '50%', stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL)
|
||||
self.brightness_mode = BrightnessMode.MODE_BRIGHT
|
||||
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
async def run(self, logger, device: str):
|
||||
logger.info('starting display event listener loop')
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
|
@ -37,7 +61,7 @@ class InputListener():
|
|||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.DEVNULL)
|
||||
|
||||
asyncio.gather(self.read_stdout(logger, proc.stdout))
|
||||
asyncio.gather(self.read_stdout(logger, proc.stdout), self.brightness_loop(logger))
|
||||
|
||||
async def sensor_loop(logger, sensor_entities):
|
||||
logger.info('starting sensor loop')
|
||||
|
|
Loading…
Reference in New Issue