Skip to content

Commit

Permalink
Fix ports
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane610 committed Oct 19, 2023
1 parent 0a34df4 commit 63a26ef
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
7 changes: 7 additions & 0 deletions axis/vapix/interfaces/param_cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
BrandT,
ImageParam,
Param,
PortParam,
PropertyParam,
PTZParam,
StreamProfileParam,
Expand Down Expand Up @@ -244,6 +245,12 @@ async def update_ports(self) -> None:
self.update(OUTPUT),
)

@property
def port_params(self) -> PortParam:
"""Provide port parameters."""
data = self[INPUT].raw | self[OUTPUT].raw | self[IOPORT].raw
return PortParam.decode(data)

@property
def nbrofinput(self) -> int:
"""Match the number of configured inputs."""
Expand Down
34 changes: 34 additions & 0 deletions axis/vapix/models/param_cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,40 @@ def decode(cls, data: dict[str, str]) -> Self:
)


@dataclass
class PortParam(ApiItem):
"""Port parameters."""

nbr_of_input: int
nbr_of_output: int
ports: dict

@classmethod
def decode(cls, data: dict[str, str]) -> Self:
"""Decode dictionary to class object."""
inputs = int(data["NbrOfInputs"])
outputs = int(data["NbrOfOutputs"])
attributes = (
"Usage",
"Configurable",
"Direction",
"Input.Name",
"Input.Trig",
"Output.Active",
"Output.Button",
"Output.DelayTime",
"Output.Mode",
"Output.Name",
"Output.PulseTime",
)
return cls(
id="port",
nbr_of_input=inputs,
nbr_of_output=outputs,
ports=process_dynamic_group(data, "I", attributes, range(inputs + outputs)),
)


@dataclass
class PropertyParam(ApiItem):
"""Property parameters."""
Expand Down
23 changes: 14 additions & 9 deletions tests/test_param_cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ async def test_update_ports(params: Params):
)

await params.update_ports()
port_param = params.port_params

assert input_route.called
assert input_route.calls.last.request.method == "GET"
Expand All @@ -383,16 +384,20 @@ async def test_update_ports(params: Params):
assert output_route.calls.last.request.method == "GET"
assert output_route.calls.last.request.url.path == "/axis-cgi/param.cgi"

assert params.nbrofinput == 1
assert params.ports == {
0: {
"Configurable": False,
"Direction": "input",
"Input.Name": "PIR sensor",
"Input.Trig": "closed",
assert port_param.nbr_of_input == params.nbrofinput == 1
assert (
port_param.ports
== params.ports
== {
0: {
"Configurable": False,
"Direction": "input",
"Input.Name": "PIR sensor",
"Input.Trig": "closed",
}
}
}
assert params.nbrofoutput == 0
)
assert port_param.nbr_of_output == params.nbrofoutput == 0


@respx.mock
Expand Down

0 comments on commit 63a26ef

Please sign in to comment.