"""
personal_handler.py
"""

from handler_library.handler import PayloadHandler
from PySide2.QtCore import Signal
import logging


class ExtraHandler(PayloadHandler):
    """
    temporay - just to check new payloads make it through to nativeUI
    """

    UpdateVersionNumber = Signal(str)
    UpdateUptimeHours = Signal(str)

    def __init__(self, *args, **kwargs):
        super().__init__(["ALARM_MUTE", "BAD_THRESHOLD", "EXPERT_INFO"], *args, **kwargs)

    def active_payload(self, payload, *args, name="Extra handler", **kwargs) -> int:
        """
        When the personal data is updated, extract those parameters needed for display
        and emit the UpdatePersonalDisplay signal.
        """
        current_data = self.get_db()
        logging.info("got a new payload:\n", current_data)
        outdict = {}
        # for key in ["name", "patient_id", "age", "sex", "height", "weight"]:
        #    outdict[key] = current_data[key]
        # self.UpdatePersonalDisplay.emit(outdict)

        if payload["type"] == "EXPERT_INFO":
            data = self.get_db()
            self.UpdateVersionNumber.emit("%s.%s.%s" % (data["version_major"], data["version_minor"], data["version_mpatch"]))
            self.UpdateUptimeHours.emit("%s" % data["uptime_hrs"])
        return 0

    def on_timeout(self): 
        pass
