Skip to content

Tasmota multiple outputs#110

Draft
hectorespert wants to merge 10 commits into
reef-pi:mainfrom
hectorespert:tasmota_multiple_outputs
Draft

Tasmota multiple outputs#110
hectorespert wants to merge 10 commits into
reef-pi:mainfrom
hectorespert:tasmota_multiple_outputs

Conversation

@hectorespert

Copy link
Copy Markdown
Contributor

This pull request refactors and enhances the Tasmota HTTP driver to support multiple outputs and improve configuration flexibility. The main changes include adding a parser for output configurations, supporting multiple digital output pins and PWM channels, and updating validation and driver creation logic to handle these improvements.

Multi-output support and driver refactor:

  • Added a new parseOutputs function to parse flexible output configuration strings (e.g., "1,2,3", "1-3,5") and return a sorted list of output numbers, with validation for duplicates and invalid formats.
  • Refactored the httpDriver struct to support multiple outputs, storing them in the outputs field, and maintaining slices of pins and channels for digital outputs and PWM, respectively.
  • Introduced pinDriver and channelDriver types to represent digital output pins and PWM channels, implementing the necessary HAL interfaces for each. [1] [2] [3]

API and interface changes:

  • Updated the PWMChannels, PWMChannel, DigitalOutputPins, and DigitalOutputPin methods to return and access the correct pin/channel objects based on the new multi-output structure. [1] [2]
  • Modified the driver instantiation logic to create the appropriate number of pin and channel objects depending on the parsed outputs, ensuring correct initialization.

Configuration and validation improvements:

  • Enhanced parameter validation to accept both string and integer types for output configuration, and to validate flexible output formats using the new parser.
  • Changed the default output parameter from "0" to "1" for improved usability.

Documentation:

  • Added a note to AGENTS.md to use the README.md file as the main reference.

hectorespert and others added 10 commits June 19, 2026 06:24
- Implement mockTasmotaServer() helper using net/http/httptest
- Simulate Tasmota device responses for Power and Dimmer commands
- Adapt existing tests to use mock instead of real device
- Remove dependency on TASMOTA_TEST_ADDRESS environment variable
- All tests now use in-memory mock server for fast, reliable testing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Implement parseOutputs() function supporting multiple formats:
  * Single output: "1"
  * Discrete outputs: "1,2,3"
  * Ranges: "1-3" or "1-5"
  * Mixed: "1-3,5,7-9"
- Validate output numbers are non-negative
- Detect duplicates and invalid ranges
- Sort outputs for consistent ordering
- Add comprehensive test coverage for all formats and edge cases
- All 18 tests pass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Implement pinDriver struct for digital output pins
  * References parent httpDriver for address
  * Stores individual output number
  * Implements Name(), Number(), Write(), LastState() methods
- Implement channelDriver struct for PWM channels
  * References parent httpDriver for address
  * Stores individual output number
  * Implements Name(), Number(), Set(), LastState() methods
- Both structs use parent driver's HTTP methods for requests
- All 18 tests pass with backward compatibility maintained

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Update httpDriver struct to hold slices of outputs, pins, and channels
- Refactor NewDriver factory method to parse output configuration and create multiple pin/channel objects
- Update ValidateParameters to accept both string and integer output formats
- Parse output configuration using parseOutputs() function
- Create pin and channel objects for each configured output
- Maintain backward compatibility with single output configurations
- Add Close() and Write() methods to channel/pin drivers
- All 18 tests pass with multi-output support ready

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Update DigitalOutputPins() to return pins slice from driver
- Update DigitalOutputPin(index) to return pin by index with bounds checking
- Update PWMChannels() to return channels slice from driver
- Update PWMChannel(index) to return channel by index with bounds checking
- Add proper error messages for out-of-bounds access
- All 18 tests pass, backward compatibility maintained

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add test for multiple discrete outputs (1,2,3)
  * Verify correct number of pins and channels returned
  * Test independent control of each digital output
  * Test PWM Set functionality for each channel
- Add test for output ranges (1-3)
  * Verify range expansion to individual outputs
  * Test independent pin control
- Add test for out-of-bounds access
  * Verify error handling for invalid pin/channel indices
- Add backward compatibility test with integer output format
- All 22 tests pass including original tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Test valid output format variations (single, discrete, ranges, mixed)
- Test invalid output configurations (empty, negative, duplicates, reversed ranges)
- Test missing address parameter
- Test empty address parameter
- Test invalid address type
- Test missing output parameter (uses default)
- All 28 tests pass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add mockErrorTasmotaServer for HTTP error testing
- Add mockMalformedJsonServer for JSON parsing error testing
- Test single output with zero index
- Test large output numbers
- Test wide output ranges (1-10)
- Test HTTP 500 error handling
- Test malformed JSON response handling
- Test multiple outputs with consistent state management
- All 34 tests pass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove 'output' int field from httpDriver struct (now uses 'outputs' slice only)
- Remove obsolete httpDriver.LastState(), Set(), and Write() methods (70 lines)
  These methods were never called after multi-output refactoring;
  pinDriver and channelDriver methods are used instead
- Simplify NewDriver() initialization by removing output field assignment
- All 34 tests pass - backward compatibility maintained
- Code is cleaner with single 'outputs' parameter handling all formats

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant