smartRules(rule: { type: SmartRuleType; channel?: number; }): Resource<SmartRules>
The region rule document of one type and channel.
Loitering on an NVR's third channel
Loitering on an NVR's third channel
import { assertEquals } from "@std/assert"; import { smartRules } from "./smart-rules.ts"; assertEquals(smartRules({ type: "regionEntrance", channel: 2 }).path, "/ISAPI/Smart/regionEntrance/2"); assertEquals(smartRules({ type: "FieldDetection" }).path, "/ISAPI/Smart/FieldDetection/1");
Parse a region entrance rule
Parse a region entrance rule
import { assertEquals } from "@std/assert"; import { smartRules } from "./smart-rules.ts"; const rules = smartRules({ type: "regionEntrance", channel: 2 }).codec.parse( "<RegionEntrance><id>2</id><enabled>true</enabled>" + "<RegionEntranceRegionList><RegionEntranceRegion><id>1</id><enabled>true</enabled>" + "<sensitivityLevel>50</sensitivityLevel><RegionCoordinatesList>" + "<RegionCoordinates><positionX>0</positionX><positionY>0</positionY></RegionCoordinates>" + "<RegionCoordinates><positionX>1000</positionX><positionY>0</positionY></RegionCoordinates>" + "<RegionCoordinates><positionX>500</positionX><positionY>1000</positionY></RegionCoordinates>" + "</RegionCoordinatesList><detectionTarget>all</detectionTarget>" + "</RegionEntranceRegion></RegionEntranceRegionList></RegionEntrance>", ); assertEquals(rules, { type: "RegionEntrance", channel: 2, enabled: true, regions: [{ id: 1, enabled: true, sensitivityLevel: 50, coordinates: [{ x: 0, y: 0 }, { x: 1000, y: 0 }, { x: 500, y: 1000 }], detectionTarget: ["all"], }], });
Read through a stubbed fetch
Read through a stubbed fetch
import { assertEquals } from "@std/assert"; import { resolvesNext, spy } from "@std/testing/mock"; import { request } from "../request.ts"; import { smartRules } from "./smart-rules.ts"; const fetch = spy(resolvesNext([ new Response("<Loitering><id>4</id><enabled>false</enabled></Loitering>"), ])); const rules = await request({ baseUrl: "http://192.0.2.10", username: "admin", password: "hunter2", fetch, }, smartRules({ type: "loitering", channel: 4 })); assertEquals(rules, { type: "Loitering", channel: 4, enabled: false, regions: [] }); assertEquals(fetch.calls[0].args[0], "http://192.0.2.10/ISAPI/Smart/loitering/4");
rule: { type: SmartRuleType; channel?: number; }
The rule's path segment and video channel; the channel defaults to 1.
The resource: its path and the codec that reads any region rule by its root name.