Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion custom_components/tplink_router/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/AlexandrErohin/home-assistant-tplink-router/issues",
"requirements": ["tplinkrouterc6u==5.9.4"],
"version": "2.10.0"
"version": "2.11.0"
}
34 changes: 29 additions & 5 deletions custom_components/tplink_router/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
SensorEntity,
SensorEntityDescription,
)
from homeassistant.const import PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, UnitOfDataRate
from homeassistant.const import PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, UnitOfDataRate, UnitOfInformation
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from .const import DOMAIN
Expand Down Expand Up @@ -106,6 +106,29 @@ class TPLinkRouterLTESensorEntityDescription(
),
)

network_types = {
Copy link
Owner

Choose a reason for hiding this comment

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

I thought it would be more useful to move this dict to the client. So I have added this to client

0: "No Service",
1: "GSM",
2: "WCDMA",
3: "4G LTE",
4: "TD-SCDMA",
5: "CDMA 1x",
6: "CDMA 1x Ev-Do",
7: "4G+ LTE"
}

sim_statuses = {
0: "No SIM card detected or SIM card error.",
1: "No SIM card detected.",
2: "SIM card error.",
3: "SIM card prepared.",
4: "SIM locked.",
5: "SIM unlocked. Authentication succeeded.",
6: "PIN locked.",
7: "SIM card is locked permanently.",
8: "suspension of transmission",
9: "Unopened"
}

LTE_SENSOR_TYPES: tuple[TPLinkRouterLTESensorEntityDescription, ...] = (
TPLinkRouterLTESensorEntityDescription(
Expand All @@ -124,19 +147,20 @@ class TPLinkRouterLTESensorEntityDescription(
key="lte_network_type",
name="LTE Network Type",
icon="mdi:sim-outline",
value=lambda status: status.network_type,
value=lambda status: network_types[status.network_type],
),
TPLinkRouterLTESensorEntityDescription(
key="lte_sim_status",
name="LTE SIM Status",
icon="mdi:sim-outline",
value=lambda status: status.sim_status,
value=lambda status: sim_statuses[status.sim_status],
Copy link
Owner

Choose a reason for hiding this comment

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

I have added 2 properties to the client network_type_info and sim_status_info - I think it is better to keep here sim_status and network_type for automation use - it is better to check int values then string. And add 2 more sensors for network_type_info and sim_status_info to show str values. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, makes sense, closer to where that responsibility should be. Changed it accordingly, still working ok.

),
TPLinkRouterLTESensorEntityDescription(
key="lte_total_statistics",
name="LTE Total Statistics",
icon="mdi:sim-outline",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfInformation.BYTES,
value=lambda status: status.total_statistics,
),
TPLinkRouterLTESensorEntityDescription(
Expand Down Expand Up @@ -168,7 +192,7 @@ class TPLinkRouterLTESensorEntityDescription(
icon="mdi:sim-outline",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
value=lambda status: status.sig_level,
value=lambda status: status.sig_level * 25,
),
TPLinkRouterLTESensorEntityDescription(
key="lte_rsrp",
Expand All @@ -192,7 +216,7 @@ class TPLinkRouterLTESensorEntityDescription(
icon="mdi:sim-outline",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
value=lambda status: status.snr,
value=lambda status: 0.1 * status.snr,
),
TPLinkRouterLTESensorEntityDescription(
key="lte_isp_name",
Expand Down