-
Notifications
You must be signed in to change notification settings - Fork 0
merging changes #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
e71d50f
flow velocity fix
mplogas b7ee42d
ac1100 reports in mA :/
mplogas f37b128
reverted calculation for current and rather switch units mA / A
mplogas 7432ec5
solar radiation is a double
mplogas 28787f4
collecting refactoring ideas
mplogas 3617728
added statemachine.cs
mplogas ee287f9
gitignore
mplogas 3e592ff
hakone
mplogas 724af44
shinkansen-kyoto: removed consumer, moved to statemachine
mplogas b689aed
shinkansen kyoto-hiroshima: updated architecture diagram
mplogas 6a417d2
naming fixes in diagrams.drawio and message stubs in project
mplogas ce57a61
tokyo hotel lobby mass commit. summarizes stuff from 7 days of refact…
mplogas 47453b8
fixes and cleanup for new mqtt service class. mqttoptions & controlle…
mplogas 66ecdc7
updated diagrams.drawio
mplogas 92220d6
some more refactoring of the new MqttService.cs and the StateMachine.cs
mplogas 5ff783a
updated diagram
mplogas c04b62b
docs
mplogas 0d1f655
updated gitignore
mplogas 1676105
communication statemachine <-> mqttservice
mplogas 66e2620
mqtt topic doc
mplogas 9dca38c
new mqttservice!
mplogas 54230dd
improved readability/maintainability via partial classes
mplogas ff864a5
removed guid that was used to test-log instances
mplogas a68172a
renaming and cleanup of unused classes
mplogas f70cc22
moved to partial classes and added httppublishingservice (shitty name…
mplogas 8b51b8e
forgot to move the old mqtt stuff to the old folder
mplogas 81889d0
consolidated the model.
mplogas a286694
added wfc02 compatibility
mplogas d250794
updated readme
mplogas 85f6be1
fixed ns for mapping
mplogas 39b3051
added storage logging for debugging purposes
mplogas cabccfe
a delta is emitted to the mqtt service only. in theory.
mplogas f1d20bc
end-to-end and then a random newtonsoft jsonparsing error appeared
mplogas 735d87a
data is now emitted to mqtt again. after inital full emit, only chang…
mplogas 25bf9cb
HA discovery added, ha restart triggers re-emit of sensor data. ha di…
mplogas 1311388
Phase 1: dead code cleanup, docs refresh, unit tests
mplogas 6f991c7
Phase 2: fix wiring gaps, add stale discovery removal
mplogas fb69e97
Phase 3: implement subdevice commands, fix WFC02 battery mapping
mplogas e193e43
config changes
mplogas 87999dd
Update Dockerfile to .NET 10.0 base images
mplogas a0df2ee
Address PR review findings
mplogas d20bee4
removed empty, legacy folder
mplogas adf4d58
Add semver tagging to Docker build workflow
mplogas 2e8e013
v2.0 release.
mplogas f846439
Update README to reflect .NET 10
mplogas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| Ecowitt Controller is a .NET 8 / ASP.NET Core application that bridges Ecowitt weather stations and IoT subdevices (AC1100 smart plugs, WFC01/WFC02 water valves) to MQTT, with Home Assistant auto-discovery support. It receives weather data via HTTP POST from Ecowitt gateways and polls subdevices via their HTTP API, then publishes everything over MQTT. | ||
|
|
||
| ## Build & Run Commands | ||
|
|
||
| All commands run from `src/`: | ||
|
|
||
| ```bash | ||
| # Build | ||
| dotnet build Ecowitt.Controller.sln | ||
|
|
||
| # Run | ||
| dotnet run --project Ecowitt.Controller/Ecowitt.Controller.csproj | ||
|
|
||
| # Run release | ||
| dotnet run -c Release --project Ecowitt.Controller/Ecowitt.Controller.csproj | ||
|
|
||
| # Run tests (NUnit) | ||
| dotnet test EcoWitt.Controller.Tests/EcoWitt.Controller.Tests.csproj | ||
|
|
||
| # Run a single test | ||
| dotnet test EcoWitt.Controller.Tests/EcoWitt.Controller.Tests.csproj --filter "FullyQualifiedName~TestMethodName" | ||
|
|
||
| # Docker build (from src/) | ||
| docker build -t ecowitt-controller . | ||
| ``` | ||
|
|
||
| Note: the test project casing is `EcoWitt.Controller.Tests` (capital W) while the main project is `Ecowitt.Controller`. | ||
|
|
||
| ## Architecture | ||
|
|
||
| The system uses three BackgroundServices communicating through an **in-memory message bus** (SlimMessageBus): | ||
|
|
||
| ### Data Flow | ||
|
|
||
| 1. **DataController** (`Controller/DataController.cs`) — ASP.NET endpoint at `POST /data/report` receives form-encoded weather data from Ecowitt gateways, publishes `GatewayApiData` onto the bus. | ||
|
|
||
| 2. **Dispatcher** (`Service/Orchestrator/Dispatcher*.cs`) — Central orchestrator (partial class split across files). Consumes messages from both HTTP and MQTT services, manages the `DeviceStore`, performs change detection via `DeNoiserHelper`, and emits data/discovery messages. The `ConsumerHttp` partial handles gateway and subdevice API data; the `ConsumerMqtt` partial handles MQTT lifecycle and Home Assistant status events. | ||
|
|
||
| 3. **MqttService** (`Service/Mqtt/MqttService*.cs`) — Partial class split across files for consumer, publisher, discovery, and events. Connects to MQTT broker, publishes sensor data and Home Assistant discovery payloads, subscribes to HA status topic for re-emission on HA restart. | ||
|
|
||
| 4. **HttpPublishingService** (`Service/Http/HttpPublishingService*.cs`) — Polls Ecowitt gateway HTTP APIs for subdevice data on a configurable interval, publishes `SubdeviceApiAggregate` onto the bus. | ||
|
|
||
| ### Message Bus Topics (SlimMessageBus) | ||
|
|
||
| Messages are defined in `Model/Message/` (Config, Data, Event subdirs). The bus wiring is in `Program.cs`. Key flows: | ||
| - Dispatcher → MqttService: `MqttConfig`, `DeviceData`, `DeviceDataFull`, `SubdeviceData`, `SubdeviceDataFull`, `HomeAssistantDiscoveryEvent` | ||
| - MqttService → Dispatcher: `MqttServiceEvent`, `MqttConnectionEvent`, `HomeAssistantStatusEvent` | ||
| - Dispatcher → HttpPublishingService: `HttpConfig` | ||
| - HttpPublishingService → Dispatcher: `SubdeviceApiAggregate`, `HttpServiceEvent` | ||
|
|
||
| ### Key Model Layer | ||
|
|
||
| - **Device/Subdevice/Sensor** (`Model/Device.cs`, `Model/Subdevice.cs`, `Model/Sensor.cs`) — Domain model. `ISensor` has typed value accessors and change tracking via hash comparison. | ||
| - **SensorBuilder** (`Model/Mapping/SensorBuilder*.cs`) — Partial class that maps raw Ecowitt property names (e.g., `tempinf`, `baromrelin`) to typed `Sensor` objects with unit conversion (imperial→metric). This is the main mapping to extend when adding new sensor types. | ||
| - **ApiDataExtension** (`Model/Mapping/ApiDataExtension.cs`) — Extension methods that convert API DTOs to domain objects. | ||
| - **DiscoveryBuilder** (`Model/Discovery/`) — Builds Home Assistant MQTT discovery payloads. | ||
| - **DeNoiserHelper** (`Service/Orchestrator/DeNoiser.cs`) — Filters insignificant sensor value changes using configurable tolerances per sensor type. | ||
| - **DeviceStore** (`Service/Orchestrator/DeviceStore.cs`) — Thread-safe in-memory store (`ConcurrentDictionary`) for gateway/subdevice state. | ||
|
|
||
| ### Configuration | ||
|
|
||
| Three option classes bound from `appsettings.json` sections in `Model/Configuration/`: | ||
| - `ecowitt` → `EcowittOptions` (gateways, polling interval, autodiscovery) | ||
| - `mqtt` → `MqttOptions` (broker connection) | ||
| - `controller` → `ControllerOptions` (units, precision, publishing interval, HA discovery toggle) | ||
|
|
||
| Config is loaded from `/config/appsettings.json` (Docker) or the content root (bare-metal). | ||
|
|
||
| ## Conventions | ||
|
|
||
| - Partial classes are used extensively for service separation (consumers, publishers, events in separate files). | ||
| - Logging uses Serilog with structured logging templates (not string interpolation). | ||
| - HTTP retry policy uses Polly with decorrelated jitter backoff. | ||
| - The Ecowitt gateway HTTP API endpoints used: `get_iot_device_list`, `parse_quick_cmd_iot`. | ||
| - SensorType/SensorState/SensorCategory enums align with Home Assistant device classes. |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README states this is a ".NET 8 bridge", but the project file and Dockerfile in this PR target .NET 10 (
net10.0,mcr.microsoft.com/dotnet/*:10.0). This inconsistency will confuse users and can lead to build/runtime issues if they follow the docs.Update the README to match the actual target/runtime (or revert the target framework/runtime versions to .NET 8 if that was the intent).