Skip to content

state.poll

state.poll

High level poll action decisions.

Decide which model operation to execute based on triggers and keyboard actions.

ACTION_GEO_RECHECK = 'geo_recheck' module-attribute

ACTION_CLEAR_CACHE = 'clear_cache' module-attribute

ACTION_CACHE_TERMINAL = 'cache_terminal' module-attribute

ACTION_NORMAL_POLL = 'normal_poll' module-attribute

RECHECK_TRIGGERS = {'menu_recheck_geoip', 'btn_check_databases'} module-attribute

PollDecision dataclass

Describe which poll action to execute.

Source code in state/poll.py
20
21
22
23
24
@dataclass(frozen=True)
class PollDecision:
    """Describe which poll action to execute."""

    action: str

_extract_key_action(key_action)

Extract action string from key_action store payload.

Source code in state/poll.py
27
28
29
30
31
32
def _extract_key_action(key_action: Any) -> str | None:
    """Extract action string from key_action store payload."""
    if not isinstance(key_action, dict):
        return None
    action = key_action.get("action")
    return action if isinstance(action, str) and action else None

decide_poll_action(*, trigger, key_action)

Decide which high level poll action to execute.

Handles direct menu clicks and keyboard actions. Otherwise returns normal_poll.

Source code in state/poll.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def decide_poll_action(*, trigger: Any, key_action: Any) -> PollDecision:
    """Decide which high level poll action to execute.

    Handles direct menu clicks and keyboard actions. Otherwise returns normal_poll.
    """
    if trigger in RECHECK_TRIGGERS:
        return PollDecision(action=ACTION_GEO_RECHECK)

    if trigger == "menu_clear_cache":
        return PollDecision(action=ACTION_CLEAR_CACHE)

    if trigger == "menu_cache_terminal":
        return PollDecision(action=ACTION_CACHE_TERMINAL)

    if trigger == "key_action":
        action = _extract_key_action(key_action)
        if action == "menu_recheck_geoip":
            return PollDecision(action=ACTION_GEO_RECHECK)
        if action == "menu_clear_cache":
            return PollDecision(action=ACTION_CLEAR_CACHE)
        if action == "menu_cache_terminal":
            return PollDecision(action=ACTION_CACHE_TERMINAL)

    return PollDecision(action=ACTION_NORMAL_POLL)