44
55import json
66import re
7- from collections .abc import Iterator
7+ from collections .abc import Iterator , Mapping
88from typing import Any , cast
99
1010from attr import define , field
2424 UpdateBoxStatus ,
2525 UpdateCriticityLevel ,
2626)
27- from pyoverkiz .enums .command import OverkizCommand , OverkizCommandParam
27+ from pyoverkiz .enums .command import OverkizCommand
2828from pyoverkiz .enums .protocol import Protocol
2929from pyoverkiz .enums .server import APIType , Server
3030from pyoverkiz .obfuscate import obfuscate_email , obfuscate_id , obfuscate_string
31- from pyoverkiz .types import DATA_TYPE_TO_PYTHON , StateType
31+ from pyoverkiz .types import DATA_TYPE_TO_PYTHON , CommandParameterValue , StateType
3232
3333# ---------------------------------------------------------------------------
3434# State & command primitives
@@ -129,8 +129,8 @@ def _cast_json_value(self, raw_value: str) -> StateType:
129129
130130
131131@define (init = False )
132- class States :
133- """Container of State objects providing lookup and mapping helpers ."""
132+ class States ( Mapping [ str , State ]) :
133+ """Container of State objects implementing Mapping[str, State] ."""
134134
135135 _states : list [State ]
136136 _index : dict [str , State ]
@@ -142,9 +142,9 @@ def __init__(self, states: list[State] | None = None) -> None:
142142 self ._index = {state .name : state for state in self ._states }
143143 self ._pos = {state .name : i for i , state in enumerate (self ._states )}
144144
145- def __iter__ (self ) -> Iterator [State ]:
146- """Return an iterator over contained State objects ."""
147- return self ._states . __iter__ ( )
145+ def __iter__ (self ) -> Iterator [str ]:
146+ """Return an iterator over state names ."""
147+ return iter ( self ._index )
148148
149149 def __contains__ (self , name : object ) -> bool :
150150 """Return True if a state with the given name exists in the container."""
@@ -172,10 +172,6 @@ def __len__(self) -> int:
172172 """Return number of states in the container."""
173173 return len (self ._states )
174174
175- def get (self , name : str ) -> State | None :
176- """Return the State with the given name or None if missing."""
177- return self ._index .get (name )
178-
179175 def select (self , names : list [str ]) -> State | None :
180176 """Return the first State that exists and has a non-None value, or None."""
181177 for name in names :
@@ -204,8 +200,8 @@ class CommandDefinition:
204200
205201
206202@define (init = False )
207- class CommandDefinitions :
208- """Container for command definitions providing convenient lookup by name ."""
203+ class CommandDefinitions ( Mapping [ str , CommandDefinition ]) :
204+ """Container for command definitions implementing Mapping[str, CommandDefinition] ."""
209205
210206 _commands : list [CommandDefinition ]
211207 _index : dict [str , CommandDefinition ]
@@ -215,9 +211,9 @@ def __init__(self, commands: list[CommandDefinition] | None = None) -> None:
215211 self ._commands = list (commands ) if commands else []
216212 self ._index = {cd .command_name : cd for cd in self ._commands }
217213
218- def __iter__ (self ) -> Iterator [CommandDefinition ]:
219- """Iterate over defined commands ."""
220- return self ._commands . __iter__ ( )
214+ def __iter__ (self ) -> Iterator [str ]:
215+ """Iterate over command names ."""
216+ return iter ( self ._index )
221217
222218 def __contains__ (self , name : object ) -> bool :
223219 """Return True if a command with `name` exists."""
@@ -234,10 +230,6 @@ def __len__(self) -> int:
234230 """Return number of command definitions."""
235231 return len (self ._commands )
236232
237- def get (self , command : str ) -> CommandDefinition | None :
238- """Return the command definition or None if missing."""
239- return self ._index .get (command )
240-
241233 def select (self , commands : list [str | OverkizCommand ]) -> str | None :
242234 """Return the first command name that exists in this definition, or None."""
243235 return next (
@@ -283,7 +275,7 @@ class Command:
283275 """Represents an OverKiz Command."""
284276
285277 name : str | OverkizCommand
286- parameters : list [str | int | float | OverkizCommandParam ] | None = None
278+ parameters : list [CommandParameterValue ] | None = None
287279 type : int | None = None
288280
289281 def to_payload (self ) -> dict [str , object ]:
0 commit comments