Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions TestSolenoid/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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():
Expand All @@ -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"],
}
}
38 changes: 2 additions & 36 deletions frontend/src/pages/profile/components/AddHardwareModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -70,7 +66,7 @@ function AddHardwareModal({ open, onClose, loggers, groups }) {
setGroupId('')
setSensorType('')
setSubmitted(false)
setPhysicalPin('')

createHardwareMutation.reset()
}

Expand All @@ -88,8 +84,6 @@ function AddHardwareModal({ open, onClose, loggers, groups }) {

if (nextHardwareType === HARDWARE_TYPES.ACTUATOR) {
setSensorType('')
} else {
setPhysicalPin('')
}
}

Expand All @@ -106,7 +100,6 @@ function AddHardwareModal({ open, onClose, loggers, groups }) {
loggerId,
groupId: groupId || null,
sensorType: isSensor ? sensorType : undefined,
...(!isSensor && { physicalPin: Number(physicalPin) }),
})
resetForm()
onClose()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -330,32 +322,6 @@ function AddHardwareModal({ open, onClose, loggers, groups }) {
</Alert>
)}

{!isSensor && (
<FormControl fullWidth required error={submitted && !pinIsValid}>
<InputLabel id="add-solenoid-pin-label">
Physical Pin
</InputLabel>
<Select
labelId="add-solenoid-pin-label"
label="Physical Pin"
value={physicalPin}
onChange={(event) => setPhysicalPin(event.target.value)}
disabled={createHardwareMutation.isPending}
>
{SOLENOID_PIN_OPTIONS.map((pin) => (
<MenuItem key={pin} value={pin}>
Pin {pin}
</MenuItem>
))}
</Select>
<FormHelperText>
{submitted && !pinIsValid
? 'Select a physical pin for this solenoid.'
: 'The board header pin connected to this solenoid.'}
</FormHelperText>
</FormControl>
)}

{!isSensor && (
<Alert severity="info">
Actuators are currently registered as solenoids and begin in the
Expand Down
36 changes: 1 addition & 35 deletions frontend/src/pages/profile/components/EditHardwareModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -306,32 +299,6 @@ function EditHardwareModal({ open, onClose, hardware, loggers, groups }) {
</Alert>
)}

{!isSensor && (
<FormControl fullWidth required error={submitted && !pinIsValid}>
<InputLabel id="edit-solenoid-pin-label">
Physical Pin
</InputLabel>
<Select
labelId="edit-solenoid-pin-label"
label="Physical Pin"
value={physicalPin}
onChange={(event) => setPhysicalPin(event.target.value)}
disabled={updateHardwareMutation.isPending}
>
{SOLENOID_PIN_OPTIONS.map((pin) => (
<MenuItem key={pin} value={pin}>
Pin {pin}
</MenuItem>
))}
</Select>
<FormHelperText>
{submitted && !pinIsValid
? 'Select a physical pin for this solenoid.'
: 'The board header pin connected to this solenoid.'}
</FormHelperText>
</FormControl>
)}

{!isSensor && (
<TextField
label="Actuator Type"
Expand Down Expand Up @@ -388,7 +355,6 @@ EditHardwareModal.propTypes = {
loggerId: PropTypes.number,
groupId: PropTypes.string,
subtype: PropTypes.string,
physicalPin: PropTypes.number,
}).isRequired,
loggers: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
9 changes: 2 additions & 7 deletions frontend/src/services/hardware.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export const normalizeActuator = (solenoid) => ({
uuid: solenoid.uuid,
userId: solenoid.user_id,
activeState: solenoid.active_state,
physicalPin: solenoid.physical_pin ?? null,
dateCreated: solenoid.date_created,
legacyCellId: null,
})
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)
Expand All @@ -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 = {
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/utils/solenoidPins.js

This file was deleted.

Loading
Loading