Skip to content

Commit

Permalink
Add fiber stats for livebox 4
Browse files Browse the repository at this point in the history
  • Loading branch information
cyr-ius committed May 8, 2024
1 parent a111f45 commit 8ac23f8
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions custom_components/livebox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LiveboxSensorEntityDescription(SensorEntityDescription):
SENSOR_TYPES: Final[tuple[SensorEntityDescription, ...]] = (
LiveboxSensorEntityDescription(
key="down",
name="Orange Livebox Download speed",
name="xDSL Download",
icon=DOWNLOAD_ICON,
translation_key="down_rate",
value_fn=lambda x: round(
Expand All @@ -63,7 +63,7 @@ class LiveboxSensorEntityDescription(SensorEntityDescription):
),
LiveboxSensorEntityDescription(
key="up",
name="Orange Livebox Upload speed",
name="xDSL Upload",
icon=UPLOAD_ICON,
translation_key="up_rate",
value_fn=lambda x: round(
Expand Down Expand Up @@ -189,23 +189,17 @@ class LiveboxSensorEntityDescription(SensorEntityDescription):
),
)

FIBER_MODE = ["fiber_power_rx", "fiber_power_tx", "fiber_rx", "fiber_tx"]
ADSL_MODE = ["up", "down"]


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up the sensors."""
coordinator = hass.data[DOMAIN][entry.entry_id]
entities = []
wanmode = coordinator.data.get("nmc", {}).get("WanMode", "").upper()
linktype = coordinator.data.get("wan_status", {}).get("LinkType", "").upper()
linktype = coordinator.data.get("wan_status", {}).get("LinkType", "").lower()

for description in SENSOR_TYPES:
if description.key in ADSL_MODE and "ETHERNET" in wanmode:
continue
if description.key in FIBER_MODE and "GPON" not in linktype:
if description.key in ["up", "down"] and linktype in ["gpon", "sfp"]:
continue
entities.append(LiveboxSensor(coordinator, description))

Expand Down

0 comments on commit 8ac23f8

Please sign in to comment.