import os

from lib.cputemp.service import Characteristic

from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
from gatewayconfig.logger import get_logger
import gatewayconfig.constants as constants

logger = get_logger(__name__)


class FirmwareRevisionCharacteristic(Characteristic):
    def __init__(self, service):
        Characteristic.__init__(
                self, constants.FIRMWARE_REVISION_CHARACTERISTIC_UUID,
                ["read"], service)

    def ReadValue(self, options):
        logger.debug('Read Firmware')
        # Intentionally reading the env variable each time in case it changes over
        # the application's lifetime
        firmware_version = os.getenv('FIRMWARE_VERSION')
        return string_to_dbus_encoded_byte_array(firmware_version)
Example #2
0
from time import sleep
from gpiozero import LED
from hm_pyhelper.hardware_definitions import is_rockpi, is_raspberry_pi
from gatewayconfig.gatewayconfig_shared_state import GatewayconfigSharedState
from gatewayconfig.logger import get_logger

LOGGER = get_logger(__name__)
LED_REFRESH_SECONDS = 2


class LEDProcessor:
    def __init__(self, status_led: LED, shared_state: GatewayconfigSharedState):
        self.status_led = status_led
        self.shared_state = shared_state

    def run(self):
        LOGGER.debug("LED LEDProcessor")

        if is_raspberry_pi() or is_rockpi():
            while True:
                # Blink slow if advertising bluetooth
                if(self.shared_state.is_advertising_bluetooth):
                    self.status_led.blink(1, 1, 1, False)
                # Blink fast if diagnostics are not OK
                elif(not self.shared_state.are_diagnostics_ok):
                    self.status_led.blink(0.1, 0.1, 10, False)
                # Solid if diagnostics are OK and not advertising
                else:
                    self.status_led.on()
                sleep(LED_REFRESH_SECONDS)