Add HTTP fallback mode to Pico communication service
This commit is contained in:
@@ -291,3 +291,62 @@ def test_http_client_set_relay_off():
|
||||
|
||||
assert fake_requests.urls == ["http://192.168.4.1/relay/fridge/off"]
|
||||
assert payload == {"ok": True}
|
||||
|
||||
|
||||
def test_communication_service_http_fallback_status():
|
||||
from comms.uart_client import UartClient
|
||||
from comms.http_client import HttpClient
|
||||
from comms.communication_service import CommunicationService
|
||||
|
||||
fake_uart = FakeUart()
|
||||
fake_requests = FakeRequests()
|
||||
fake_requests.responses = [
|
||||
{"type": "status_response", "battery": {"soc": 66}}
|
||||
]
|
||||
|
||||
state = AppState()
|
||||
service = CommunicationService(
|
||||
UartClient(fake_uart),
|
||||
state,
|
||||
HttpClient(fake_requests),
|
||||
)
|
||||
|
||||
service.enable_http_fallback()
|
||||
response = service.request_status()
|
||||
|
||||
assert response["type"] == "status_response"
|
||||
assert state.battery["soc"] == 66
|
||||
assert fake_uart.writes == []
|
||||
assert fake_requests.urls == ["http://192.168.4.1/status"]
|
||||
|
||||
|
||||
def test_communication_service_http_fallback_relay():
|
||||
from comms.uart_client import UartClient
|
||||
from comms.http_client import HttpClient
|
||||
from comms.communication_service import CommunicationService
|
||||
|
||||
fake_uart = FakeUart()
|
||||
fake_requests = FakeRequests()
|
||||
fake_requests.responses = [
|
||||
{
|
||||
"type": "relay_response",
|
||||
"relay": "fridge",
|
||||
"enabled": True,
|
||||
"ok": True,
|
||||
}
|
||||
]
|
||||
|
||||
state = AppState()
|
||||
service = CommunicationService(
|
||||
UartClient(fake_uart),
|
||||
state,
|
||||
HttpClient(fake_requests),
|
||||
)
|
||||
|
||||
service.enable_http_fallback()
|
||||
response = service.set_relay("fridge", True)
|
||||
|
||||
assert response["type"] == "relay_response"
|
||||
assert state.relays["fridge"] is True
|
||||
assert fake_uart.writes == []
|
||||
assert fake_requests.urls == ["http://192.168.4.1/relay/fridge/on"]
|
||||
|
||||
Reference in New Issue
Block a user