summaryrefslogtreecommitdiff
path: root/src/home/mqtt/_module.py
blob: ef50e7042febade0ece9b33200eabd3430568249 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from __future__ import annotations

import abc
import logging

from typing import TYPE_CHECKING, Optional
if TYPE_CHECKING:
    from ._node import MqttNode
    from ._payload import MqttPayload


class MqttModule(abc.ABC):
    tick_interval: int
    _initialized: bool

    def __init__(self, tick_interval=0):
        self.tick_interval = tick_interval
        self._initialized = False
        self._logger = logging.getLogger(self.__class__.__name__)

    def init(self, mqtt: MqttNode):
        pass

    def is_initialized(self):
        return self._initialized

    def set_initialized(self):
        self._initialized = True

    def tick(self, mqtt: MqttNode):
        pass

    def handle_payload(self, mqtt: MqttNode, topic: str, payload: bytes) -> Optional[MqttPayload]:
        pass