Skip to content

Commit

Permalink
Merge pull request #87 from PimDoos/dev
Browse files Browse the repository at this point in the history
Disable wifi RSSI sensor when API is null
  • Loading branch information
PimDoos authored Mar 29, 2024
2 parents 7d60234 + 8117076 commit 4163bbc
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions custom_components/sessy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
device = hass.data[DOMAIN][config_entry.entry_id][SESSY_DEVICE]
sensors = []

sensors.append(
SessySensor(hass, config_entry, "WiFi RSSI",
SessyApiCommand.NETWORK_STATUS, "wifi_sta.rssi",
SensorDeviceClass.SIGNAL_STRENGTH, SensorStateClass.MEASUREMENT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
entity_category=EntityCategory.DIAGNOSTIC)
)
try:
# Disable WiFi RSSI sensor if WiFi is not connected on discovery
network_status: dict = get_cache_command(hass, config_entry, SessyApiCommand.NETWORK_STATUS)
wifi_rssi_present = network_status.get("wifi_sta", dict()).get("rssi", None) != None
if wifi_rssi_present:
sensors.append(
SessySensor(hass, config_entry, "WiFi RSSI",
SessyApiCommand.NETWORK_STATUS, "wifi_sta.rssi",
SensorDeviceClass.SIGNAL_STRENGTH, SensorStateClass.MEASUREMENT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
entity_category=EntityCategory.DIAGNOSTIC)
)
except Exception as e:
_LOGGER.warning(f"Error setting up WiFi RSSI sensor: {e}")


for memory_type in ("internal","external"):
sensors.append(
Expand Down

0 comments on commit 4163bbc

Please sign in to comment.