Skip to content

Commit 45dde8f

Browse files
committed
Cleaned diagnostic sensors in sensor.py (not needed anymore)
Performance update #42
1 parent 8304daf commit 45dde8f

File tree

2 files changed

+1
-74
lines changed

2 files changed

+1
-74
lines changed

custom_components/zte_router/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"iot_class": "local_polling",
1010
"issue_tracker": "https://github.com/Kajkac/ZTE-MC-Home-assistant-repo/issues",
1111
"requirements": ["aiohttp"],
12-
"version": "1.0.49b13"
12+
"version": "1.0.49b14"
1313
}

custom_components/zte_router/sensor.py

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
6969
monthly_rx_gb(coordinator),
7070
DataLeftSensor(coordinator),
7171
ConnectionUptimeSensor(coordinator),
72-
ZTESessionDiagnosticsSensor(coordinator),
7372
])
7473
handled_keys.update(["station_list", "lan_station_list", "all_devices"])
7574

@@ -299,78 +298,6 @@ def extra_state_attributes(self):
299298
# Only return attributes if self._attributes is defined
300299
return getattr(self, "_attributes", {})
301300

302-
class ZTESessionDiagnosticsSensor(ZTERouterEntity):
303-
def __init__(self, coordinator):
304-
self.coordinator = coordinator
305-
self._name = "Session Diagnostics"
306-
self._state = None
307-
self._attributes = {}
308-
self.entity_registry_enabled_default = True
309-
self._attr_is_diagnostics = True
310-
self._attr_should_poll = False
311-
self._state = "Unavailable" if not self.coordinator.last_update_success else "OK"
312-
_LOGGER.info("Initializing Session Diagnostics sensor")
313-
314-
@property
315-
def name(self):
316-
return self._name
317-
318-
@property
319-
def state(self):
320-
return self._state or "Unknown"
321-
322-
@property
323-
def unique_id(self):
324-
return f"{DOMAIN}_{self.coordinator.ip_entry}_session_diagnostics"
325-
326-
@property
327-
def device_info(self):
328-
return {
329-
"identifiers": {(DOMAIN, f"{DOMAIN}_{self.coordinator.ip_entry}")},
330-
"name": self.coordinator.ip_entry,
331-
"manufacturer": MANUFACTURER,
332-
"model": MODEL,
333-
}
334-
335-
@property
336-
def is_diagnostics(self):
337-
return True
338-
339-
@property
340-
def entity_category(self):
341-
return EntityCategory.DIAGNOSTIC
342-
343-
@property
344-
def extra_state_attributes(self):
345-
return self._attributes
346-
347-
async def async_update(self):
348-
_LOGGER.info("Manual update requested for Session Diagnostics sensor")
349-
await self.coordinator.async_request_refresh()
350-
351-
@guard_stale_data
352-
async def async_handle_coordinator_update(self):
353-
output = await self.coordinator.hass.async_add_executor_job(
354-
self.coordinator.run_mc_script,
355-
self.coordinator.ip_entry,
356-
self.coordinator.password_entry,
357-
self.coordinator.username_entry,
358-
99 # Your diagnostic command
359-
)
360-
361-
try:
362-
data = json.loads(extract_json(output))
363-
self._state = "OK" if data else "Unavailable"
364-
self._attributes = data
365-
_LOGGER.info(f"Session Diagnostics sensor updated: {data}")
366-
except Exception as e:
367-
_LOGGER.warning(f"Failed to parse session diagnostics output: {e}")
368-
self._state = "Error"
369-
self._attributes = {}
370-
371-
self.async_write_ha_state()
372-
373-
374301
class ZTERouterSensor(ZTERouterEntity):
375302
def __init__(self, coordinator, name, key, disabled_by_default=False):
376303
self.coordinator = coordinator

0 commit comments

Comments
 (0)