summaryrefslogtreecommitdiff
path: root/src/home/mqtt/_module.py
blob: 840534ea7f8ae69df0969ce9b43b630451d11a84 (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
35
36
37
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 unset_initialized(self):
        self._initialized = False

    def tick(self, mqtt: MqttNode):
        pass

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