Tasmota multiple outputs#110
Draft
hectorespert wants to merge 10 commits into
Draft
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
parseOutputsfunction 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.httpDriverstruct to support multiple outputs, storing them in theoutputsfield, and maintaining slices ofpinsandchannelsfor digital outputs and PWM, respectively.pinDriverandchannelDrivertypes to represent digital output pins and PWM channels, implementing the necessary HAL interfaces for each. [1] [2] [3]API and interface changes:
PWMChannels,PWMChannel,DigitalOutputPins, andDigitalOutputPinmethods to return and access the correct pin/channel objects based on the new multi-output structure. [1] [2]Configuration and validation improvements:
"0"to"1"for improved usability.Documentation:
AGENTS.mdto use theREADME.mdfile as the main reference.