mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
Merge pull request #116 from cjkas/feat/usb-only-firmware
feat: say when the firmware is flashed over USB
This commit is contained in:
commit
11a7088dd3
13 changed files with 72 additions and 19 deletions
|
|
@ -16,7 +16,7 @@ Runs against a real device on your network, by hand, never in CI. It checks sock
|
|||
| `--lockout` | on a Secured device, also fail `/login` until this PC is refused, then wait out the 30 s lockout |
|
||||
| `--record` | save hello, the sync and the schema to `test/fixtures/proto2/`, for the web UI and Home Assistant tests |
|
||||
|
||||
A plain run sends nothing on air, changes no setting (it saves only values the device already has) and doesn't reboot the device. The command tests send ops that are refused before they reach the radio, and one `setPositions` that sets a shade to the position the sync gave: that drops the fraction of a percent the shade's believed position may have had. The edit tests send edits that are refused, and one shade sort order set to the order it has, which saves the shades again unchanged. The settings tests send saves that are refused, and one that saves the NTP server and time zone the device already has. The restore test sends options that aren't JSON with a file that isn't a backup, so nothing is restored. The frequency scan test pauses the radio's sending for a second or two, as a scan does. It does fill every socket slot for a few seconds, and replays a page load.
|
||||
A plain run sends nothing on air, changes no setting (it saves only values the device already has) and doesn't reboot the device. The command tests send ops that are refused before they reach the radio, and one `setPositions` that sets a shade to the position the sync gave: that drops the fraction of a percent the shade's believed position may have had. The edit tests send edits that are refused, and one shade sort order set to the order it has, which saves the shades again unchanged. The settings tests send saves that are refused, and one that saves the NTP server and time zone the device already has. The restore test sends options that aren't JSON with a file that isn't a backup, so nothing is restored. A firmware upload goes only to a device without an OTA slot, which refuses it. The frequency scan test pauses the radio's sending for a second or two, as a scan does. It does fill every socket slot for a few seconds, and replays a page load.
|
||||
|
||||
The web UI holds one of the device's 5 socket slots for each open tab, and Home Assistant holds one. The tests that fill every slot fill the ones left, so close the UI's tabs for the full load.
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ import urllib.request
|
|||
|
||||
import pytest
|
||||
|
||||
from proto_client import ProtoClient
|
||||
from proto_client import ProtoClient, run_sync
|
||||
from test_settings import header, uptime
|
||||
|
||||
# Every route that needs the token under Secured, sent without a body or
|
||||
# parameters, so a route that let one through would still change nothing.
|
||||
|
|
@ -169,3 +170,20 @@ def test_a_socket_from_the_page_the_device_served_is_accepted(host, token):
|
|||
c.close()
|
||||
# The device frees the slot when it sees the disconnect.
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
def test_a_firmware_upload_without_an_ota_slot_is_refused(host, token, connect, schema):
|
||||
"""Builds with one app slot (C6, debug) say so in the header, and refuse
|
||||
the upload without stopping the radio or rebooting."""
|
||||
_, frames, _ = run_sync(connect(schema=schema.hash))
|
||||
# Left out at its default, true, as is a field older firmware doesn't have.
|
||||
if header(schema, frames).get("hasOtaSlot", True):
|
||||
pytest.skip("the device has an OTA slot: an upload would start an update")
|
||||
uptime_before = uptime(schema, frames)
|
||||
status, _, body = upload(host, "/updateFirmware", auth(token))
|
||||
assert status == 400, body
|
||||
assert "no OTA slot" in json.loads(body)["desc"]
|
||||
# The old reply rebooted half a second later.
|
||||
time.sleep(2)
|
||||
_, frames, _ = run_sync(connect(schema=schema.hash))
|
||||
assert uptime(schema, frames) > uptime_before, "the device restarted"
|
||||
|
|
|
|||
|
|
@ -86,9 +86,8 @@ def test_a_save_tells_the_other_clients(connect, schema):
|
|||
def test_a_wifi_scan_lists_the_networks(connect, schema):
|
||||
c = connect(schema=schema.hash)
|
||||
_, frames, _ = run_sync(c)
|
||||
header = next(schema.expand(f["d"][schema.keys["header"]]) for f in frames if schema.keys["header"] in f["d"])
|
||||
# The connection in use: Ethernet with WiFi as the fallback may be on either.
|
||||
if header.get("connType") != "Wifi":
|
||||
if header(schema, frames).get("connType") != "Wifi":
|
||||
pytest.skip("the device isn't on WiFi")
|
||||
assert is_ok(schema, op(c, schema, "scanWifi", {}))
|
||||
found = c.recv_until(lambda f: f["t"] == schema.type_numbers["wifiNetworks"], timeout=20)[-1]
|
||||
|
|
@ -152,6 +151,12 @@ def wait_for_restart(host, token, schema, uptime_before):
|
|||
time.sleep(2)
|
||||
|
||||
|
||||
def header(schema, frames):
|
||||
"""The header a sync starts with."""
|
||||
key = schema.keys["header"]
|
||||
return next(schema.expand(f["d"][key]) for f in frames if key in f["d"])
|
||||
|
||||
|
||||
def uptime(schema, frames):
|
||||
"""The uptime, in ms, from the status a sync ends with."""
|
||||
key = schema.keys["status"]
|
||||
|
|
|
|||
|
|
@ -37,6 +37,19 @@ test('a field the sync left out is its default', () => {
|
|||
for (const g of m.groupList()) assert.ok(Array.isArray(g.linkedShades));
|
||||
});
|
||||
|
||||
test('the device has an OTA slot unless it says it has none', () => {
|
||||
// The recording is from firmware before the field.
|
||||
assert.equal(synced().header.hasOtaSlot, undefined);
|
||||
const schema = recordedSchema();
|
||||
schema.add({ F: [['os', 'hasOtaSlot', 'b', 1]] });
|
||||
const header = deviceSections(schema).find((d) => d.header).header;
|
||||
const m = new ProtoModel(schema);
|
||||
m.applySync({ header: header });
|
||||
assert.equal(m.header.hasOtaSlot, true);
|
||||
m.applySync({ header: schema.expand(Object.assign({ os: 0 }, schema.pack(header))) });
|
||||
assert.equal(m.header.hasOtaSlot, false);
|
||||
});
|
||||
|
||||
test('the lists come in their sort order', () => {
|
||||
const m = synced();
|
||||
const orders = m.shadeList().map((s) => s.sortOrder);
|
||||
|
|
|
|||
|
|
@ -119,15 +119,17 @@ static void test_values_at_their_default_are_left_out() {
|
|||
w.add(proto_field_t::myPos, (int8_t)-1);
|
||||
w.add(proto_field_t::repeats, (uint8_t)1);
|
||||
w.add(proto_field_t::paired, false);
|
||||
w.add(proto_field_t::hasOtaSlot, true); // a bool whose default is true
|
||||
w.add(proto_field_t::name, "");
|
||||
w.add(proto_field_t::name, (const char *)nullptr);
|
||||
}).c_str());
|
||||
}
|
||||
static void test_values_off_their_default_are_written_by_key() {
|
||||
TEST_ASSERT_EQUAL_STRING("{\"p\":50,\"m\":0,\"i\":1,\"n\":\"Office\",\"a\":4294967295,\"q\":-5}", writeObject([](ProtoWriter &w) {
|
||||
TEST_ASSERT_EQUAL_STRING("{\"p\":50,\"m\":0,\"i\":1,\"os\":0,\"n\":\"Office\",\"a\":4294967295,\"q\":-5}", writeObject([](ProtoWriter &w) {
|
||||
w.add(proto_field_t::position, (int8_t)50);
|
||||
w.add(proto_field_t::myPos, (int8_t)0);
|
||||
w.add(proto_field_t::paired, true);
|
||||
w.add(proto_field_t::hasOtaSlot, false);
|
||||
w.add(proto_field_t::name, "Office");
|
||||
w.add(proto_field_t::remoteAddress, (uint32_t)0xFFFFFFFF);
|
||||
w.add(proto_field_t::tiltPosition, (int8_t)-5);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue