Skip to content

Commit 6a1c984

Browse files
committed
Add SSID information as device sensor (FR #813)
1 parent b267df2 commit 6a1c984

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

custom_components/smartthinq_sensors/device_helpers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ def power_state(self):
117117
return STATE_ON
118118
return STATE_OFF
119119

120+
@property
121+
def ssid(self):
122+
"""The device network SSID."""
123+
return self._api.device.device_info.ssid
124+
120125
def get_features_attributes(self):
121126
"""Return a dict with device features and name."""
122127
ret_val = {}

custom_components/smartthinq_sensors/diagnostics.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from homeassistant.components.diagnostics import async_redact_data
5+
from homeassistant.components.diagnostics import REDACTED, async_redact_data
66
from homeassistant.config_entries import ConfigEntry
77
from homeassistant.const import CONF_TOKEN
88
from homeassistant.core import HomeAssistant, callback
@@ -14,6 +14,7 @@
1414

1515
TO_REDACT = {CONF_TOKEN}
1616
TO_REDACT_DEV = {"macAddress", "ssid", "userNo"}
17+
TO_REDACT_STATE = {"macAddress", "ssid"}
1718

1819

1920
async def async_get_config_entry_diagnostics(
@@ -137,6 +138,12 @@ def _async_device_ha_info(hass: HomeAssistant, lg_device_id: str) -> dict | None
137138
# The context doesn't provide useful information in this case.
138139
state_dict.pop("context", None)
139140

141+
if state_dict and "state" in state_dict:
142+
for to_redact in TO_REDACT_STATE:
143+
if entity_entry.entity_id.endswith(f"_{to_redact}"):
144+
state_dict["state"] = REDACTED
145+
break
146+
140147
data["entities"][entity_entry.entity_id] = {
141148
"name": entity_entry.name,
142149
"original_name": entity_entry.original_name,

custom_components/smartthinq_sensors/sensor.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,15 @@ class ThinQSensorEntityDescription(SensorEntityDescription):
533533
**{dev_type: WASH_DEV_SENSORS for dev_type in WASH_DEVICE_TYPES},
534534
}
535535

536+
COMMON_SENSORS: tuple[ThinQSensorEntityDescription, ...] = (
537+
ThinQSensorEntityDescription(
538+
key="ssid",
539+
name="SSID",
540+
icon="mdi:access-point-network",
541+
value_fn=lambda x: x.ssid,
542+
),
543+
)
544+
536545

537546
def _sensor_exist(
538547
lge_device: LGEDevice, sensor_desc: ThinQSensorEntityDescription
@@ -572,7 +581,14 @@ def _async_discover_device(lge_devices: dict) -> None:
572581
if _sensor_exist(lge_device, sensor_desc)
573582
]
574583

575-
async_add_entities(lge_sensors)
584+
lge_common_sensors = [
585+
LGESensor(lge_device, sensor_desc, get_wrapper_device(lge_device, dev_type))
586+
for sensor_desc in COMMON_SENSORS
587+
for dev_type in lge_devices.keys()
588+
for lge_device in lge_devices.get(dev_type, [])
589+
]
590+
591+
async_add_entities(lge_sensors + lge_common_sensors)
576592

577593
_async_discover_device(lge_cfg_devices)
578594

custom_components/smartthinq_sensors/wideq/device_info.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ def device_state(self) -> str | None:
251251
"""Return the status associated to the device."""
252252
return self._data.get("deviceState")
253253

254+
@property
255+
def ssid(self) -> str | None:
256+
"""Return the network ssid associated to the device."""
257+
return self._data.get("ssid")
258+
254259
@property
255260
def snapshot(self) -> dict[str, Any] | None:
256261
"""Return the snapshot data associated to the device."""

0 commit comments

Comments
 (0)