Skip to content

Commit

Permalink
feat(hardware): added safety relay active state to HepaUVState and sa…
Browse files Browse the repository at this point in the history
…fety_relay_inactive error (#15311)
  • Loading branch information
vegano1 committed Jun 18, 2024
1 parent 1ea906e commit 29d7d79
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions hardware/opentrons_hardware/firmware_bindings/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
by default. Please do not unconditionally import things outside the python standard
library.
"""

from enum import Enum, unique
from typing import Union, Dict, List

Expand Down Expand Up @@ -294,6 +295,7 @@ class ErrorCode(int, Enum):
door_open = 0x0E
reed_open = 0x0F
motor_driver_error_detected = 0x10
safety_relay_inactive = 0x11


@unique
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Payloads of can bus messages."""

# TODO (amit, 2022-01-26): Figure out why using annotations import ruins
# dataclass fields interpretation.
# from __future__ import annotations
Expand Down Expand Up @@ -684,6 +685,7 @@ class GetHepaUVStatePayloadResponse(EmptyPayload):
uv_light_on: utils.UInt8Field
remaining_time_s: utils.UInt32Field
uv_current_ma: utils.UInt16Field
safety_relay_active: utils.UInt8Field


@dataclass(eq=False)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for controlling the hepa/uv extension module."""

import logging
import asyncio
from typing import Optional
Expand Down Expand Up @@ -46,6 +47,7 @@ class HepaUVState:
uv_duration_s: int
remaining_time_s: int
uv_current_ma: int
safety_relay_active: bool


async def set_hepa_fan_state(
Expand Down Expand Up @@ -136,6 +138,7 @@ def _listener(message: MessageDefinition, arb_id: ArbitrationId) -> None:
uv_duration_s=int(message.payload.uv_duration_s.value),
remaining_time_s=int(message.payload.remaining_time_s.value),
uv_current_ma=int(message.payload.uv_current_ma.value),
safety_relay_active=bool(message.payload.safety_relay_active.value),
)

def _filter(arb_id: ArbitrationId) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def create_hepa_uv_state_response(
duration: int,
remaining_time: int,
uv_current: int,
safety_relay_active: bool,
) -> MessageDefinition:
"""Create a GetHepaUVStateResponse."""
return md.GetHepaUVStateResponse(
Expand All @@ -63,6 +64,7 @@ def create_hepa_uv_state_response(
uv_duration_s=UInt32Field(duration),
remaining_time_s=UInt32Field(remaining_time),
uv_current_ma=UInt16Field(uv_current),
safety_relay_active=UInt8Field(safety_relay_active),
)
)

Expand Down Expand Up @@ -162,12 +164,29 @@ def responder(
[
(
NodeId.host,
create_hepa_uv_state_response(True, 900, 300, 3300),
create_hepa_uv_state_response(True, 900, 300, 3300, True),
NodeId.hepa_uv,
),
(
NodeId.host,
create_hepa_uv_state_response(True, 0, 0, 33000, True),
NodeId.hepa_uv,
),
(
NodeId.host,
create_hepa_uv_state_response(True, 0, 0, 33000, False),
NodeId.hepa_uv,
),
(
NodeId.host,
create_hepa_uv_state_response(False, 0, 0, 0, True),
NodeId.hepa_uv,
),
(
NodeId.host,
create_hepa_uv_state_response(False, 900, 0, 0, False),
NodeId.hepa_uv,
),
(NodeId.host, create_hepa_uv_state_response(True, 0, 0, 33000), NodeId.hepa_uv),
(NodeId.host, create_hepa_uv_state_response(False, 0, 0, 0), NodeId.hepa_uv),
(NodeId.host, create_hepa_uv_state_response(False, 900, 0, 0), NodeId.hepa_uv),
],
)
async def test_get_hepa_uv_state(
Expand Down Expand Up @@ -202,6 +221,7 @@ def responder(
int(payload.uv_duration_s.value),
int(payload.remaining_time_s.value),
int(payload.uv_current_ma.value),
bool(payload.safety_relay_active.value),
)
== res
)

0 comments on commit 29d7d79

Please sign in to comment.