Skip to content

v2.0 refactoring#10

Merged
mplogas merged 39 commits intomainfrom
refactor-static
Mar 3, 2026
Merged

v2.0 refactoring#10
mplogas merged 39 commits intomainfrom
refactor-static

Conversation

@mplogas
Copy link
Owner

@mplogas mplogas commented Mar 2, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 2, 2026 23:00
mplogas added 28 commits March 3, 2026 00:03
…roptions need to be mapped to mqttconfig in statemachine before sending
…, i agree). most of the data now arrives in the state machine and device store.
mplogas added 7 commits March 3, 2026 00:03
…scovery topics are now retained. dynamically removing subdevices and sensors need to be implemented
Remove unused code: ConcurrentSensors, GatewayOptions.Passkey, HttpHost.Passkey,
HealthCheck.cs, old/ directory (superseded), in-source docs (moved to docs/).
Fix solarradiation to use BuildDoubleSensor (value can be decimal).
Upgrade both projects to net10.0, add InternalsVisibleTo for test access.

Add 7 test files (150 tests) covering SensorBuilder, SensorBuilder.Addon,
DeNoiserHelper, MqttPathBuilder, MqttPayloadBuilder, DiscoveryBuilder,
and ApiDataExtension. Update docs/api.md, docs/mqtt.md, README.md, CLAUDE.md.
Fix switch discovery: publish HA switch config for WFC01/AC1100/WFC02.
Fix HA reconnect: re-emit discovery on HomeAssistant online status.
Fix gateway HTTP auth: add Basic auth header when credentials configured.
Wire ecowitt.retries config to Polly retry policy.
Remove unused PublishingInterval from config, model, and docs.
Add DiscoveryRemovalEvent to clear retained HA discovery for stale sensors.
Register SubdeviceApiCommand on the message bus so MQTT commands
reach the Dispatcher. Add SendSubdeviceCommand to HttpPublishingService
with the correct gateway payload format (position, always_on, content-type
application/json). Wire the Dispatcher handler to resolve the gateway and
subdevice, default bare HA ON to always-on, and delegate to
HttpPublishingService. Remove old commented-out SendCommand from Dispatcher.

Fix WFC02 battery reporting 5% instead of 100% by using
BuildBatterySensor with the x20 multiplier (5 bars = 100%).
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR performs a v2.0 refactor of Ecowitt.Controller, restructuring the application into an orchestrated, message-bus-driven architecture with new HTTP/MQTT services, updated models/mapping, expanded tests, and reorganized documentation.

Changes:

  • Replaces legacy polling/publishing/background services with Dispatcher + MqttService + HttpPublishingService connected via SlimMessageBus.
  • Refactors domain models and mapping (new Sensor model with SensorDataType, updated SensorBuilder, and a DeNoiserHelper).
  • Moves/rewrites docs under docs/, updates README/solution layout, and adds/updates NUnit tests.

Reviewed changes

Copilot reviewed 80 out of 86 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/docker-compose.yml Updates bind-mount paths for dev containers.
src/Ecowitt.Controller/mqtt.md Removes old in-project MQTT notes (migrated to docs/).
src/Ecowitt.Controller/ha_discovery_payload.md Removes old HA discovery payload examples (migrated to docs/).
src/Ecowitt.Controller/appsettings.json Adjusts example/local config values for MQTT + gateway definition.
src/Ecowitt.Controller/Subdevice/SubdeviceService.cs Removes legacy subdevice polling background service.
src/Ecowitt.Controller/Store/DataPublishService.cs Removes legacy MQTT data publishing service.
src/Ecowitt.Controller/Service/Orchestrator/Dispatcher.cs Adds central orchestrator that emits configs and publishes device/subdevice events.
src/Ecowitt.Controller/Service/Orchestrator/Dispatcher.ConsumerMqtt.cs Adds MQTT-related event consumers (HA status, connection/service events).
src/Ecowitt.Controller/Service/Orchestrator/Dispatcher.ConsumerHttp.cs Adds HTTP/subdevice/gateway data consumers and store update logic.
src/Ecowitt.Controller/Service/Orchestrator/DeviceStore.cs Moves/renames store to orchestrator namespace and updates types to Device.
src/Ecowitt.Controller/Service/Orchestrator/DeNoiser.cs Adds tolerance-based change detection helper.
src/Ecowitt.Controller/Service/Mqtt/MqttService.cs Introduces new MQTT service (heartbeat, HA subscriptions, discovery emission).
src/Ecowitt.Controller/Service/Mqtt/MqttService.Publisher.cs Adds publishing helpers for gateway/subdevice payloads and availability.
src/Ecowitt.Controller/Service/Mqtt/MqttService.Events.cs Adds MQTTnet event handlers (message receive, connect/disconnect).
src/Ecowitt.Controller/Service/Mqtt/MqttService.DiscoveryPublisher.cs Adds HA discovery publishing logic.
src/Ecowitt.Controller/Service/Mqtt/MqttService.Consumer.cs Adds SlimMessageBus consumers for configs/data/discovery removal.
src/Ecowitt.Controller/Service/Mqtt/MqttPayloadBuilder.cs Extracts MQTT payload shaping into a dedicated helper.
src/Ecowitt.Controller/Service/Mqtt/MqttPathBuilder.cs Renames/moves MQTT topic builder from legacy Helper.
src/Ecowitt.Controller/Service/Http/HttpPublishingService.cs Adds new HTTP polling + command publishing service for subdevices.
src/Ecowitt.Controller/Service/Http/HttpPublishingService.Events.cs Adds polling loop + lifecycle events for HTTP service.
src/Ecowitt.Controller/Service/Http/HttpPublishingService.Consumer.cs Adds consumer to receive HttpConfig updates.
src/Ecowitt.Controller/Program.cs Rewires DI + SlimMessageBus topics/consumers and hosted services.
src/Ecowitt.Controller/Mqtt/MqttService.cs Removes legacy MQTT background service implementation.
src/Ecowitt.Controller/Mqtt/MqttClient.cs Removes legacy MQTT client wrapper.
src/Ecowitt.Controller/Model/SubdeviceApiAggregate.cs Removes legacy aggregate model (moved under message/data).
src/Ecowitt.Controller/Model/Subdevice.cs Adds WFC02 model enum value.
src/Ecowitt.Controller/Model/Sensor.cs Replaces generic sensor model with a unified Sensor + SensorDataType.
src/Ecowitt.Controller/Model/Message/Event/MqttServiceEvent.cs Adds MQTT service lifecycle event model.
src/Ecowitt.Controller/Model/Message/Event/MqttConnectionEvent.cs Adds MQTT connection event model.
src/Ecowitt.Controller/Model/Message/Event/HttpServiceEvent.cs Adds HTTP service lifecycle event model.
src/Ecowitt.Controller/Model/Message/Event/HomeAssistantStatusEvent.cs Adds HA online/offline status event model.
src/Ecowitt.Controller/Model/Message/Event/HomeAssistantDiscoveryEvent.cs Adds event to trigger HA discovery publishing.
src/Ecowitt.Controller/Model/Message/Event/DiscoveryRemovalEvent.cs Adds event to remove stale discovery configs.
src/Ecowitt.Controller/Model/Message/Data/SubdeviceDataFull.cs Adds “full subdevice snapshot” data message.
src/Ecowitt.Controller/Model/Message/Data/SubdeviceData.cs Adds “changed subdevice sensors” data message.
src/Ecowitt.Controller/Model/Message/Data/SubdeviceApiAggregate.cs Adds message-wrapped subdevice aggregate payload.
src/Ecowitt.Controller/Model/Message/Data/DeviceDataFull.cs Adds “full gateway snapshot” data message.
src/Ecowitt.Controller/Model/Message/Data/DeviceData.cs Adds “changed gateway sensors” data message.
src/Ecowitt.Controller/Model/Message/Config/MqttConfig.cs Adds bus-delivered MQTT runtime config message.
src/Ecowitt.Controller/Model/Message/Config/HttpConfig.cs Adds bus-delivered HTTP polling config + host model.
src/Ecowitt.Controller/Model/Mapping/SensorBuilder.cs Updates mapping logic, namespaces, and adds/adjusts sensor cases.
src/Ecowitt.Controller/Model/Mapping/SensorBuilder.Builder.cs Adds parsing/build helpers (unit conversion, invalid token handling).
src/Ecowitt.Controller/Model/Mapping/SensorBuilder.Addon.cs Updates addon/calculated sensor logic for new Device/Sensor model.
src/Ecowitt.Controller/Model/Mapping/ApiDataExtension.cs Updates API DTO → domain mapping and namespaces.
src/Ecowitt.Controller/Model/Discovery/Origin.cs Moves discovery models under Model.Discovery.
src/Ecowitt.Controller/Model/Discovery/Enums.cs Moves discovery enums under Model.Discovery.
src/Ecowitt.Controller/Model/Discovery/DiscoveryBuilder.cs Updates discovery builder namespace + origin version string.
src/Ecowitt.Controller/Model/Discovery/Device.cs Moves discovery device model under Model.Discovery.
src/Ecowitt.Controller/Model/Discovery/Config.cs Moves discovery config model under Model.Discovery.
src/Ecowitt.Controller/Model/Discovery/Availability.cs Moves discovery availability model under Model.Discovery.
src/Ecowitt.Controller/Model/Device.cs Renames GatewayDevice and removes unused concurrent bag.
src/Ecowitt.Controller/Model/Configuration/MqttOptions.cs Moves options under Model.Configuration.
src/Ecowitt.Controller/Model/Configuration/EcowittOptions.cs Moves options under Model.Configuration and adjusts gateway options.
src/Ecowitt.Controller/Model/Configuration/ControllerOptions.cs Moves options under Model.Configuration and removes publishing interval.
src/Ecowitt.Controller/Model/Api/SubdeviceApiData.cs Moves API DTO under Model.Api.
src/Ecowitt.Controller/Model/Api/SubdeviceApiCommand.cs Moves API DTO under Model.Api.
src/Ecowitt.Controller/Model/Api/GatewayApiData.cs Moves API DTO under Model.Api and adds defaults.
src/Ecowitt.Controller/Mapping/SensorBuilderLogic.cs Removes legacy builder logic file (replaced by new builder partials).
src/Ecowitt.Controller/Ecowitt.Controller.sln Adds a solution file under project directory.
src/Ecowitt.Controller/Ecowitt.Controller.csproj Updates project metadata and package/layout items.
src/Ecowitt.Controller/Discovery/DiscoveryPublishService.cs Removes legacy discovery publisher background service.
src/Ecowitt.Controller/Controller/DataController.cs Updates controller to new namespaces and structured logging.
src/Ecowitt.Controller/Consumer/DataConsumer.cs Removes legacy consumers (replaced by Dispatcher).
src/Ecowitt.Controller/Consumer/CommandConsumer.cs Removes legacy command consumer (replaced by Dispatcher + HttpPublishingService).
src/Ecowitt.Controller.sln Updates root solution organization and solution items.
src/EcoWitt.Controller.Tests/SubdeviceMappingTest.cs Updates tests for new namespaces and sensor counts.
src/EcoWitt.Controller.Tests/SensorMappingTest.cs Updates tests for the new Sensor model and SensorDataType.
src/EcoWitt.Controller.Tests/SensorBuilderTest.cs Adds extensive coverage for sensor mapping/building logic.
src/EcoWitt.Controller.Tests/SensorBuilderAddonTest.cs Adds tests for calculated/addon sensor generation.
src/EcoWitt.Controller.Tests/MqttPayloadBuilderTest.cs Adds tests for MQTT payload building.
src/EcoWitt.Controller.Tests/MqttPathBuilderTest.cs Adds tests for MQTT topic/path building.
src/EcoWitt.Controller.Tests/DiscoveryBuilderTest.cs Adds tests for HA discovery payload builders.
src/EcoWitt.Controller.Tests/DeNoiserTest.cs Adds tests for tolerance-based change detection.
src/EcoWitt.Controller.Tests/ApiDataExtensionTest.cs Adds tests for API DTO → domain mapping.
src/EcoWitt.Controller.Tests/EcoWitt.Controller.Tests.csproj Updates test project metadata/target framework.
src/.idea/.idea.Ecowitt.Controller/.idea/vcs.xml Adds Rider/JetBrains project metadata (workspace-specific).
src/.idea/.idea.Ecowitt.Controller/.idea/indexLayout.xml Adds Rider/JetBrains project metadata (workspace-specific).
src/.idea/.idea.Ecowitt.Controller/.idea/encodings.xml Adds Rider/JetBrains project metadata (workspace-specific).
src/.idea/.idea.Ecowitt.Controller/.idea/.name Adds Rider/JetBrains project metadata (workspace-specific).
src/.idea/.idea.Ecowitt.Controller/.idea/.gitignore Adds Rider/JetBrains project metadata (workspace-specific).
docs/mqtt.md Adds consolidated MQTT topic/payload/discovery documentation.
docs/api.md Adds consolidated HTTP API and polling documentation.
README.md Rewrites README with clearer setup/docs links and v2.0 feature summary.
CLAUDE.md Adds repo guidance file documenting architecture and conventions.
.gitignore Expands ignores (including .idea/, vscode, backups).
Files not reviewed (5)
  • src/.idea/.idea.Ecowitt.Controller/.idea/.gitignore: Language not supported
  • src/.idea/.idea.Ecowitt.Controller/.idea/.name: Language not supported
  • src/.idea/.idea.Ecowitt.Controller/.idea/encodings.xml: Language not supported
  • src/.idea/.idea.Ecowitt.Controller/.idea/indexLayout.xml: Language not supported
  • src/.idea/.idea.Ecowitt.Controller/.idea/vcs.xml: Language not supported
Comments suppressed due to low confidence (1)

src/Ecowitt.Controller/Service/Orchestrator/DeviceStore.cs:45

  • Spelling: log message says "Updateing" → "Updating".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mplogas added 4 commits March 3, 2026 00:10
The project was upgraded to net10.0 but the Dockerfile still
referenced dotnet/sdk:8.0 and dotnet/aspnet:8.0, causing the
Docker build CI action to fail.
- Fix null guard in MqttService Subscribe/UnsubscribeHomeAssistant
  that would NRE when _client is null (condition was inverted)
- Replace throw in MQTT callback JSON deserialization with log+return
  to prevent crashing the MQTT client callback path
- Include port in HttpHost.BaseUrl when non-default
- Add explicit WithConsumer<Dispatcher> for GatewayApiData on bus
- Remove .idea/ files from source control (already in .gitignore)
- Reset appsettings.json to generic defaults (no local dev values)
- Fix "Updateing" typo in DeviceStore log message
Trigger on v* tags to produce versioned container images (e.g. v2.0.0
generates 2.0.0, 2.0, 2 tags). Skip push on PR builds. Keep latest
tag for main branch pushes.
@mplogas mplogas merged commit 2e8e013 into main Mar 3, 2026
1 check passed
@mplogas mplogas deleted the refactor-static branch March 4, 2026 10:53
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.

2 participants