diff --git a/TestSolenoid/app/main.py b/TestSolenoid/app/main.py
index c66d2fd..b1902f7 100644
--- a/TestSolenoid/app/main.py
+++ b/TestSolenoid/app/main.py
@@ -7,12 +7,15 @@
SolenoidState = Literal["open", "closed"]
+
class StateUpdate(BaseModel):
state: SolenoidState
+
class StatusResponse(BaseModel):
state: SolenoidState
+
app = FastAPI(
title="Test Solenoid",
description="Solenoid sim with open and closed state",
@@ -33,26 +36,26 @@ class StatusResponse(BaseModel):
state_lock = asyncio.Lock()
+
@app.get("/health")
async def health():
return {
"status": "healthy",
}
+
@app.get("/status", response_model=StatusResponse)
async def get_status():
- return {
- "state": solenoid["state"]
- }
+ return {"state": solenoid["state"]}
+
@app.put("/status", response_model=StatusResponse)
async def update_status(update: StateUpdate):
async with state_lock:
solenoid["state"] = update.state
- return {
- "state": solenoid["state"]
- }
+ return {"state": solenoid["state"]}
+
@app.post("/open", response_model=StatusResponse)
async def open_solenoid():
@@ -62,10 +65,11 @@ async def open_solenoid():
"state": solenoid["state"],
}
+
@app.post("/close", response_model=StatusResponse)
async def close_solenoid():
async with state_lock:
solenoid["state"] = "closed"
return {
"state": solenoid["state"],
- }
\ No newline at end of file
+ }
diff --git a/frontend/src/pages/profile/components/AddHardwareModal.jsx b/frontend/src/pages/profile/components/AddHardwareModal.jsx
index 7c59c50..b41b8c7 100644
--- a/frontend/src/pages/profile/components/AddHardwareModal.jsx
+++ b/frontend/src/pages/profile/components/AddHardwareModal.jsx
@@ -26,7 +26,6 @@ import {
useSensorTypes,
} from '../../../services/hardware'
import { formatSensorType } from '../../../utils/sensorTypes'
-import { SOLENOID_PIN_OPTIONS } from '../../../utils/solenoidPins'
const getErrorMessage = (error) => {
const detail = error?.response?.data?.detail
@@ -53,15 +52,12 @@ function AddHardwareModal({ open, onClose, loggers, groups }) {
const [groupId, setGroupId] = useState('')
const [sensorType, setSensorType] = useState('')
const [submitted, setSubmitted] = useState(false)
- const [physicalPin, setPhysicalPin] = useState('')
const isSensor = hardwareType === HARDWARE_TYPES.SENSOR
- const pinIsValid =
- physicalPin !== '' && SOLENOID_PIN_OPTIONS.includes(Number(physicalPin))
const formIsValid =
name.trim().length > 0 &&
loggerId !== '' &&
- (isSensor ? sensorType !== '' : pinIsValid)
+ (!isSensor || sensorType !== '')
const resetForm = () => {
setHardwareType(HARDWARE_TYPES.SENSOR)
@@ -70,7 +66,7 @@ function AddHardwareModal({ open, onClose, loggers, groups }) {
setGroupId('')
setSensorType('')
setSubmitted(false)
- setPhysicalPin('')
+
createHardwareMutation.reset()
}
@@ -88,8 +84,6 @@ function AddHardwareModal({ open, onClose, loggers, groups }) {
if (nextHardwareType === HARDWARE_TYPES.ACTUATOR) {
setSensorType('')
- } else {
- setPhysicalPin('')
}
}
@@ -106,7 +100,6 @@ function AddHardwareModal({ open, onClose, loggers, groups }) {
loggerId,
groupId: groupId || null,
sensorType: isSensor ? sensorType : undefined,
- ...(!isSensor && { physicalPin: Number(physicalPin) }),
})
resetForm()
onClose()
@@ -227,7 +220,6 @@ function AddHardwareModal({ open, onClose, loggers, groups }) {
value={loggerId}
onChange={(event) => {
setLoggerId(event.target.value)
- if (!isSensor) setPhysicalPin('')
}}
disabled={
createHardwareMutation.isPending || loggers.length === 0
@@ -330,32 +322,6 @@ function AddHardwareModal({ open, onClose, loggers, groups }) {
)}
- {!isSensor && (
-
-
- Physical Pin
-
-
-
- {submitted && !pinIsValid
- ? 'Select a physical pin for this solenoid.'
- : 'The board header pin connected to this solenoid.'}
-
-
- )}
-
{!isSensor && (
Actuators are currently registered as solenoids and begin in the
diff --git a/frontend/src/pages/profile/components/EditHardwareModal.jsx b/frontend/src/pages/profile/components/EditHardwareModal.jsx
index 9f3d59d..9cd8a93 100644
--- a/frontend/src/pages/profile/components/EditHardwareModal.jsx
+++ b/frontend/src/pages/profile/components/EditHardwareModal.jsx
@@ -26,7 +26,6 @@ import {
useSensorTypes,
} from '../../../services/hardware'
import { formatSensorType } from '../../../utils/sensorTypes'
-import { SOLENOID_PIN_OPTIONS } from '../../../utils/solenoidPins'
const getErrorMessage = (error) => {
const detail = error?.response?.data?.detail
@@ -57,15 +56,11 @@ function EditHardwareModal({ open, onClose, hardware, loggers, groups }) {
isSensor ? (hardware.subtype ?? '') : '',
)
const [submitted, setSubmitted] = useState(false)
- const [physicalPin, setPhysicalPin] = useState(hardware.physicalPin ?? '')
-
- const pinIsValid =
- physicalPin !== '' && SOLENOID_PIN_OPTIONS.includes(Number(physicalPin))
const formIsValid =
name.trim().length > 0 &&
loggerId !== '' &&
- (isSensor ? sensorType !== '' : pinIsValid)
+ (!isSensor || sensorType !== '')
const handleClose = () => {
if (updateHardwareMutation.isPending) {
@@ -91,7 +86,6 @@ function EditHardwareModal({ open, onClose, hardware, loggers, groups }) {
loggerId,
groupId: groupId || null,
sensorType: isSensor ? sensorType : undefined,
- ...(!isSensor && { physicalPin: Number(physicalPin) }),
})
onClose()
} catch {
@@ -203,7 +197,6 @@ function EditHardwareModal({ open, onClose, hardware, loggers, groups }) {
value={loggerId}
onChange={(event) => {
setLoggerId(event.target.value)
- if (!isSensor) setPhysicalPin('')
}}
disabled={
updateHardwareMutation.isPending || loggers.length === 0
@@ -306,32 +299,6 @@ function EditHardwareModal({ open, onClose, hardware, loggers, groups }) {
)}
- {!isSensor && (
-
-
- Physical Pin
-
-
-
- {submitted && !pinIsValid
- ? 'Select a physical pin for this solenoid.'
- : 'The board header pin connected to this solenoid.'}
-
-
- )}
-
{!isSensor && (
({
uuid: solenoid.uuid,
userId: solenoid.user_id,
activeState: solenoid.active_state,
- physicalPin: solenoid.physical_pin ?? null,
dateCreated: solenoid.date_created,
legacyCellId: null,
})
@@ -105,7 +104,7 @@ export const getSensorTypes = (axiosPrivate) =>
export const createHardware = (
axiosPrivate,
- { hardwareType, name, loggerId, groupId, sensorType, physicalPin },
+ { hardwareType, name, loggerId, groupId, sensorType },
) => {
const endpoint = getHardwareEndpoint(hardwareType)
const payload = {
@@ -115,8 +114,6 @@ export const createHardware = (
}
if (hardwareType === HARDWARE_TYPES.SENSOR) {
payload.sensor_type = sensorType
- } else if (physicalPin !== undefined && physicalPin !== '') {
- payload.physical_pin = physicalPin === null ? null : Number(physicalPin)
}
return axiosPrivate
.post(`${endpoint}/`, payload)
@@ -125,7 +122,7 @@ export const createHardware = (
export const updateHardware = (
axiosPrivate,
- { hardwareType, backendId, name, loggerId, groupId, sensorType, physicalPin },
+ { hardwareType, backendId, name, loggerId, groupId, sensorType },
) => {
const endpoint = getHardwareEndpoint(hardwareType)
const payload = {
@@ -135,8 +132,6 @@ export const updateHardware = (
}
if (hardwareType === HARDWARE_TYPES.SENSOR) {
payload.sensor_type = sensorType
- } else if (physicalPin !== undefined && physicalPin !== '') {
- payload.physical_pin = physicalPin === null ? null : Number(physicalPin)
}
return axiosPrivate
.put(`${endpoint}/${backendId}`, payload)
diff --git a/frontend/src/utils/solenoidPins.js b/frontend/src/utils/solenoidPins.js
deleted file mode 100644
index ca27e1d..0000000
--- a/frontend/src/utils/solenoidPins.js
+++ /dev/null
@@ -1,3 +0,0 @@
-export const SOLENOID_PIN_OPTIONS = [
- 3, 5, 8, 10, 15, 16, 18, 19, 21, 22, 23, 24, 27, 28, 29, 31, 33, 35, 36, 37,
-]
diff --git a/frontend/tests/components/profile/HardwareModal.test.jsx b/frontend/tests/components/profile/HardwareModal.test.jsx
index 58524a4..39431c4 100644
--- a/frontend/tests/components/profile/HardwareModal.test.jsx
+++ b/frontend/tests/components/profile/HardwareModal.test.jsx
@@ -9,7 +9,6 @@ import {
useSensorTypes,
useUpdateHardware,
} from '../../../src/services/hardware'
-import { SOLENOID_PIN_OPTIONS } from '../../../src/utils/solenoidPins'
vi.mock('../../../src/auth/hooks/useAxiosPrivate', () => ({
default: () => ({}),
@@ -31,7 +30,6 @@ const actuator = {
hardwareType: 'actuator',
name: 'Greenhouse Valve',
loggerId: 123,
- physicalPin: 16,
}
async function chooseOption(user, label, option) {
@@ -39,7 +37,7 @@ async function chooseOption(user, label, option) {
await user.click(await screen.findByRole('option', { name: option }))
}
-describe('hardware modal solenoid pins', () => {
+describe('hardware modals', () => {
let createMutation
let updateMutation
@@ -64,7 +62,7 @@ describe('hardware modal solenoid pins', () => {
})
})
- it('requires an actuator pin, submits it as a number, and resets after adding', async () => {
+ it('creates an actuator without a pin while sensor types load and resets after adding', async () => {
const user = userEvent.setup()
const onClose = vi.fn()
useSensorTypes.mockReturnValue({
@@ -76,10 +74,10 @@ describe('hardware modal solenoid pins', () => {
,
)
+ await chooseOption(user, /Category/, 'Actuator')
expect(
screen.queryByRole('combobox', { name: /Physical Pin/ }),
).not.toBeInTheDocument()
- await chooseOption(user, /Category/, 'Actuator')
await user.type(
screen.getByRole('textbox', { name: /Hardware Name/ }),
'Valve',
@@ -89,16 +87,6 @@ describe('hardware modal solenoid pins', () => {
const addButton = screen.getByRole('button', { name: 'Add Hardware' })
expect(addButton).toBeEnabled()
await user.click(addButton)
- expect(createMutation.mutateAsync).not.toHaveBeenCalled()
-
- await user.click(screen.getByRole('combobox', { name: /Physical Pin/ }))
- expect(
- screen.getAllByRole('option').map((option) => option.textContent),
- ).toEqual(SOLENOID_PIN_OPTIONS.map((pin) => `Pin ${pin}`))
- await user.click(
- screen.getByRole('option', { name: 'Pin 16', exact: true }),
- )
- await user.click(addButton)
expect(createMutation.mutateAsync).toHaveBeenCalledWith({
hardwareType: 'actuator',
@@ -106,33 +94,59 @@ describe('hardware modal solenoid pins', () => {
loggerId: 123,
groupId: null,
sensorType: undefined,
- physicalPin: 16,
})
expect(onClose).toHaveBeenCalledOnce()
- await chooseOption(user, /Category/, 'Actuator')
+ expect(screen.getByRole('textbox', { name: /Hardware Name/ })).toHaveValue(
+ '',
+ )
expect(
- screen.getByRole('combobox', { name: /Physical Pin/ }),
- ).not.toHaveTextContent(/Pin \d/)
+ screen.getByRole('combobox', { name: /Category/ }),
+ ).toHaveTextContent('Sensor')
+ expect(
+ screen.getByRole('combobox', { name: /Logger/ }),
+ ).not.toHaveTextContent('Greenhouse Board')
+ expect(createMutation.reset).toHaveBeenCalledOnce()
})
- it('clears the selected pin when switching categories and omits it from sensors', async () => {
+ it('still requires a name and logger when adding an actuator', async () => {
const user = userEvent.setup()
render(
,
)
await chooseOption(user, /Category/, 'Actuator')
- await chooseOption(user, /Physical Pin/, 'Pin 18')
- await chooseOption(user, /Category/, 'Sensor')
+ const nameInput = screen.getByRole('textbox', { name: /Hardware Name/ })
+ await user.type(nameInput, 'Valve')
+ await user.click(screen.getByRole('button', { name: 'Add Hardware' }))
+ expect(createMutation.mutateAsync).not.toHaveBeenCalled()
+
+ await chooseOption(user, /Logger/, 'Greenhouse Board')
+ await user.clear(nameInput)
+ await user.type(nameInput, ' ')
+ await user.click(screen.getByRole('button', { name: 'Add Hardware' }))
+ expect(createMutation.mutateAsync).not.toHaveBeenCalled()
+ })
+
+ it('requires a sensor type again after switching categories and creates a sensor', async () => {
+ const user = userEvent.setup()
+ render(
+ ,
+ )
+ await chooseOption(user, /Sensor Type/, 'Soil Moisture')
await chooseOption(user, /Category/, 'Actuator')
expect(
- screen.getByRole('combobox', { name: /Physical Pin/ }),
- ).not.toHaveTextContent(/Pin \d/)
+ screen.queryByRole('combobox', { name: /Sensor Type/ }),
+ ).not.toBeInTheDocument()
await chooseOption(user, /Category/, 'Sensor')
+ expect(
+ screen.getByRole('combobox', { name: /Sensor Type/ }),
+ ).not.toHaveTextContent('Soil Moisture')
await user.type(
screen.getByRole('textbox', { name: /Hardware Name/ }),
'Soil Sensor',
)
await chooseOption(user, /Logger/, 'Greenhouse Board')
+ await user.click(screen.getByRole('button', { name: 'Add Hardware' }))
+ expect(createMutation.mutateAsync).not.toHaveBeenCalled()
await chooseOption(user, /Sensor Type/, 'Soil Moisture')
await user.click(screen.getByRole('button', { name: 'Add Hardware' }))
@@ -145,7 +159,7 @@ describe('hardware modal solenoid pins', () => {
})
})
- it('preselects a saved pin and saves a changed pin', async () => {
+ it('edits an actuator without displaying or submitting a pin', async () => {
const user = userEvent.setup()
render(
{
)
expect(
- screen.getByRole('combobox', { name: /Physical Pin/ }),
- ).toHaveTextContent('Pin 16')
- await chooseOption(user, /Physical Pin/, 'Pin 22')
+ screen.queryByRole('combobox', { name: /Physical Pin/ }),
+ ).not.toBeInTheDocument()
+ const nameInput = screen.getByRole('textbox', { name: /Hardware Name/ })
+ await user.clear(nameInput)
+ await user.type(nameInput, 'Updated Valve')
await user.click(screen.getByRole('button', { name: 'Save Changes' }))
expect(updateMutation.mutateAsync).toHaveBeenCalledWith({
hardwareType: 'actuator',
backendId: 9,
- name: 'Greenhouse Valve',
+ name: 'Updated Valve',
loggerId: 123,
groupId: null,
sensorType: undefined,
- physicalPin: 22,
})
})
- it('requires a new pin after changing an actuator logger', async () => {
+ it('changes an actuator logger without requiring a pin', async () => {
const user = userEvent.setup()
render(
{
)
await chooseOption(user, /Logger/, 'Garden Board')
- expect(
- screen.getByRole('combobox', { name: /Physical Pin/ }),
- ).not.toHaveTextContent(/Pin \d/)
await user.click(screen.getByRole('button', { name: 'Save Changes' }))
- expect(updateMutation.mutateAsync).not.toHaveBeenCalled()
- await chooseOption(user, /Physical Pin/, 'Pin 3')
- await user.click(screen.getByRole('button', { name: 'Save Changes' }))
- expect(updateMutation.mutateAsync).toHaveBeenCalledWith(
- expect.objectContaining({ loggerId: 456, physicalPin: 3 }),
- )
- })
-
- it('leaves legacy unconfigured pins empty until one is selected', async () => {
- const user = userEvent.setup()
- render(
- ,
- )
-
- expect(
- screen.getByRole('combobox', { name: /Physical Pin/ }),
- ).not.toHaveTextContent(/Pin \d/)
- await user.click(screen.getByRole('button', { name: 'Save Changes' }))
- expect(updateMutation.mutateAsync).not.toHaveBeenCalled()
+ expect(updateMutation.mutateAsync).toHaveBeenCalledWith({
+ hardwareType: 'actuator',
+ backendId: 9,
+ name: 'Greenhouse Valve',
+ loggerId: 456,
+ groupId: null,
+ sensorType: undefined,
+ })
})
it('edits sensors without displaying or submitting a pin', async () => {
diff --git a/frontend/tests/unit/services/hardware.test.js b/frontend/tests/unit/services/hardware.test.js
index 78e7836..fc749cd 100644
--- a/frontend/tests/unit/services/hardware.test.js
+++ b/frontend/tests/unit/services/hardware.test.js
@@ -85,19 +85,11 @@ describe('hardware service', () => {
uuid: 'actuator-uuid',
userId: 'user-uuid',
activeState: 'closed',
- physicalPin: 16,
dateCreated: '2026-08-24T12:00:00',
legacyCellId: null,
})
})
- it.each([undefined, null])(
- 'keeps an unconfigured actuator pin empty (%s)',
- (pin) => {
- expect(normalizeActuator({ physical_pin: pin }).physicalPin).toBeNull()
- },
- )
-
it('fetches and combines sensors and actuators', async () => {
axiosPrivate.get.mockImplementation((url) => {
if (url === '/api/sensor/') {
@@ -184,7 +176,7 @@ describe('hardware service', () => {
})
})
- it('creates an actuator without sending sensor fields', async () => {
+ it('creates an actuator without requiring a pin or sending sensor fields', async () => {
axiosPrivate.post.mockResolvedValue({
data: {
id: 11,
@@ -197,18 +189,16 @@ describe('hardware service', () => {
loggerId: 456,
groupId: null,
sensorType: 'ignored',
- physicalPin: 16,
})
expect(axiosPrivate.post).toHaveBeenCalledWith('/api/solenoid/', {
name: 'Greenhouse Valve',
logger_id: 456,
group_id: null,
- physical_pin: 16,
})
})
- it('updates hardware using its backend ID', async () => {
+ it('updates an actuator without a pin using its backend ID', async () => {
axiosPrivate.put.mockResolvedValue({
data: {
id: 9,
@@ -221,14 +211,12 @@ describe('hardware service', () => {
name: 'Updated Valve',
loggerId: 456,
groupId: null,
- physicalPin: 18,
})
expect(axiosPrivate.put).toHaveBeenCalledWith('/api/solenoid/9', {
name: 'Updated Valve',
logger_id: 456,
group_id: null,
- physical_pin: 18,
})
})
@@ -236,17 +224,17 @@ describe('hardware service', () => {
['create', createHardware, 'post'],
['update', updateHardware, 'put'],
])(
- 'does not turn an empty pin into zero on %s',
+ 'does not forward legacy actuator pin values on %s',
async (_, mutateHardware, method) => {
axiosPrivate[method].mockResolvedValue({ data: {} })
await mutateHardware(axiosPrivate, {
hardwareType: HARDWARE_TYPES.ACTUATOR,
backendId: 9,
- name: 'Valve without a configured pin',
+ name: 'Valve with legacy pin metadata',
loggerId: 456,
groupId: null,
- physicalPin: '',
+ physicalPin: 16,
})
expect(axiosPrivate[method].mock.calls[0][1]).not.toHaveProperty(