🚧 WIP
This commit is contained in:
@@ -499,6 +499,57 @@ class TestChannelRanges:
|
||||
"channel_ranges": {"AI4.0": {"min": 0}}, **base})
|
||||
assert r.status_code == 400 # missing max
|
||||
|
||||
async def test_negative_range_accepted(self, client, app):
|
||||
r = await client.put("/api/config/channel-ranges", json={
|
||||
"channel_ranges": {"AI4.0": {"min": -32000, "max": 32000}},
|
||||
"persist": False,
|
||||
})
|
||||
assert r.status_code == 200
|
||||
assert app.node.channel_range("ai", 4, 0) == (-32000, 32000)
|
||||
# layout exposes the signed range
|
||||
r = await client.get("/api/node")
|
||||
ai = next(c for m in r.json()["modules"] if m["index"] == 4
|
||||
for c in m["channels"] if c["address"] == "AI4.0")
|
||||
assert ai["range"] == {"min": -32000, "max": 32000}
|
||||
|
||||
async def test_range_floor_is_minus_65534(self, client):
|
||||
r = await client.put("/api/config/channel-ranges", json={
|
||||
"channel_ranges": {"AI4.0": {"min": -65535, "max": 0}}, "persist": False})
|
||||
assert r.status_code == 400 # below -65534
|
||||
|
||||
async def test_signed_value_display_and_write(self, client, app, datastore):
|
||||
# channel with a negative-min range -> signed two's-complement view
|
||||
await client.put("/api/config/channel-ranges", json={
|
||||
"channel_ranges": {"AI4.0": {"min": -32000, "max": 32000}},
|
||||
"persist": False})
|
||||
r = await client.post("/api/channels/ai/4/0", json={"value": -2000})
|
||||
assert r.status_code == 200
|
||||
# raw image holds the two's-complement word
|
||||
assert datastore.get_input_word(0) == (-2000) & 0xFFFF
|
||||
# values API shows the signed number again
|
||||
r = await client.get("/api/values")
|
||||
entry = next(v for v in r.json()["values"]
|
||||
if (v["kind"], v["module"], v["channel"]) == ("ai", 4, 0))
|
||||
assert entry["value"] == -2000
|
||||
|
||||
async def test_negative_ao_force(self, client, datastore):
|
||||
r = await client.post("/api/channels/ao/5/0", json={"value": -3000})
|
||||
assert r.status_code == 200
|
||||
assert datastore.get_output_word(0) == (-3000) & 0xFFFF
|
||||
# unsigned AO (default range) still displays raw
|
||||
r = await client.get("/api/values")
|
||||
entry = next(v for v in r.json()["values"]
|
||||
if (v["kind"], v["module"], v["channel"]) == ("ao", 5, 0))
|
||||
assert entry["value"] == (-3000) & 0xFFFF
|
||||
|
||||
async def test_value_bounds_rejected(self, client):
|
||||
r = await client.post("/api/channels/ai/4/0", json={"value": -65535})
|
||||
assert r.status_code == 400
|
||||
r = await client.post("/api/channels/ai/4/0", json={"value": 65536})
|
||||
assert r.status_code == 400
|
||||
r = await client.post("/api/channels/ai/4/0", json={"value": "banana"})
|
||||
assert r.status_code == 400
|
||||
|
||||
async def test_ranges_persist_to_yaml(self, client, app, tmp_path):
|
||||
cfg_file = tmp_path / "node.yaml"
|
||||
app.node_config_path = str(cfg_file)
|
||||
|
||||
Reference in New Issue
Block a user