From 710f1ab2fdaa90a51c0f2e7372f51e26aa8f546e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 16 Apr 2025 10:25:59 -1000 Subject: [PATCH] fixes --- .../components/dhcp/websocket_api.py | 42 ++++++------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/homeassistant/components/dhcp/websocket_api.py b/homeassistant/components/dhcp/websocket_api.py index 30b2b5bcf43..380332459d2 100644 --- a/homeassistant/components/dhcp/websocket_api.py +++ b/homeassistant/components/dhcp/websocket_api.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Any, TypedDict +from typing import Any import voluptuous as vol @@ -19,30 +19,12 @@ from .helpers import ( ) -class DHCPDiscovery(TypedDict): - """Typed dict for DHCP discovery.""" - - mac_address: str - hostname: str - ip_address: str - - @callback def async_setup(hass: HomeAssistant) -> None: """Set up the DHCP websocket API.""" websocket_api.async_register_command(hass, ws_subscribe_discovery) -def serialize_service_info(service_info: _DhcpServiceInfo) -> DHCPDiscovery: - """Serialize a _DhcpServiceInfo object.""" - serialized: DHCPDiscovery = { - "mac_address": dr.format_mac(service_info.macaddress).upper(), - "hostname": service_info.hostname, - "ip_address": service_info.ip, - } - return serialized - - class _DiscoverySubscription: """Class to hold and manage the subscription data.""" @@ -93,20 +75,20 @@ class _DiscoverySubscription: } ) - def _async_added(self, service_infos: list[_DhcpServiceInfo]) -> None: - self._async_event_message( - { - "add": [ - serialize_service_info(service_info) - for service_info in service_infos - ] - } - ) - @callback def _async_on_discovery(self, service_info: _DhcpServiceInfo) -> None: """Handle the callback.""" - self._async_event_message({"add": [serialize_service_info(service_info)]}) + self._async_event_message( + { + "add": [ + { + "mac_address": dr.format_mac(service_info.macaddress).upper(), + "hostname": service_info.hostname, + "ip_address": service_info.ip, + } + ] + } + ) @websocket_api.require_admin