Add WAN status sensors - #140
Open
akhoury wants to merge 1 commit into
Open
Conversation
Author
|
just noticed this one... #104 might be a better idea, either works for me as long as I can tell how my Multi-wan is doing :) |
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.
Summary
Adds a read-only sensor per WAN candidate interface (e.g.
wan,secondwan,wwan,tethering,modem_*) with three states:connected,failing(link up, no internet reachable),disconnected.What's new
SensorDeviceClass.ENUMwith optionsconnected/failing/disconnected.wan→ "Primary WAN",secondwan→ "Secondary WAN",wwan→ "WiFi Repeater",tethering→ "Phone Tether",modem_x_y_z→ "USB Modem(modem_x_y_z)", IPv6 variants get an "(IPv6)" suffix. Raw name is exposed as the
interfaceattribute for automations/templates.upat least once, then persists across HA restarts via the entity registry. New interfaces (USB modem plugged in later, etc.) appearwithout an HA restart.
router_get_statuscall. Zero new HTTP requests, nogli4pychanges.Implementation
custom_components/glinet/wan.py— pure helpers + dataclasses (state mapping, friendly names, network-array parser). No HA imports — unit-testable in isolation.custom_components/glinet/wan_sensor.py—WanStatusSensorentity class.custom_components/glinet/router.py— stops discardingresponse["network"]fromrouter_get_status(which was previously thrown away). Addswan_statusproperty,signal_wan_new/signal_wan_updatedispatcher signals, andregister_known_wan_interfaces()for platform setup.custom_components/glinet/sensor.py— registersWanStatusSensorentities from the entity registry + any currently-up interfaces; subscribes to the new-WAN signal for live discovery.custom_components/glinet/__init__.py— small refactor: movedfrom .router import GLinetRouterintoasync_setup_entry(). No production behavior change. Stops the package init from eagerlyloading HA /
gli4py, which lets unit tests importwan.pywithout those deps installed.Tests
First unit tests in this repo (partially addresses the "Add tests" README TODO):
Coverage:
(up, online)combination.Notes for review
manifest.jsonversion bump — assumed that's done at release time. Let me know if you'd prefer it bumped here.__init__.pylazy-import refactor has independent value (test isolation, faster cold-start), but I'm happy to revert it if you'd rather keep that file unchanged.Preview in HA:
Notice the
Primary WANandSecondary WANwithconnectedvalues in my setup