Skip to content

Refactor serial command handling, add HTTP handlers, and expand parser tests#29

Open
bootjp wants to merge 1 commit intomainfrom
codex/refactor-code
Open

Refactor serial command handling, add HTTP handlers, and expand parser tests#29
bootjp wants to merge 1 commit intomainfrom
codex/refactor-code

Conversation

@bootjp
Copy link
Owner

@bootjp bootjp commented Jan 31, 2026

Motivation

  • Reduce duplication and clarify serial-command flow by extracting helpers and named constants for commands and header length.
  • Make the parsing logic more testable and robust by isolating key/value parsing into a dedicated function.
  • Separate HTTP handler wiring from run to improve readability and make the HTTP endpoints easier to adjust.
  • Increase unit-test coverage for the parser to validate edge cases and input robustness.

Description

  • Introduce constants startCommand, stopCommand, and commandHeaderLines and use them where commands/header skipping are needed in main.go.
  • Extract parseKeyValue, openSerialPort, and writeCommand helper functions and update recordMetrics to use these helpers and a loop-driven header-skip instead of inline logic.
  • Add metricsHandler and indexHandler functions and register them in run instead of inlining the handler code.
  • Expand main_test.go with named subtests and additional cases (invalid values, unknown keys ignored, missing equals ignored) to exercise parser behavior.

Testing

  • Ran go test ./... and all tests passed.
  • Updated unit tests (main_test.go) and executed them as part of the test run which succeeded.

Codex Task

case "CO2":
parsed, err := strconv.ParseFloat(value, 64)
if err != nil {
return err

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
error returned from external package is unwrapped: sig: func strconv.ParseFloat(s string, bitSize int) (float64, error) (wrapcheck)

case "HUM":
parsed, err := strconv.ParseFloat(value, 64)
if err != nil {
return err

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
error returned from external package is unwrapped: sig: func strconv.ParseFloat(s string, bitSize int) (float64, error) (wrapcheck)

case "TMP":
parsed, err := strconv.ParseFloat(value, 64)
if err != nil {
return err

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
error returned from external package is unwrapped: sig: func strconv.ParseFloat(s string, bitSize int) (float64, error) (wrapcheck)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments