mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
fixes
This commit is contained in:
parent
68f6dad592
commit
710f1ab2fd
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, TypedDict
|
from typing import Any
|
||||||
|
|
||||||
import voluptuous as vol
|
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
|
@callback
|
||||||
def async_setup(hass: HomeAssistant) -> None:
|
def async_setup(hass: HomeAssistant) -> None:
|
||||||
"""Set up the DHCP websocket API."""
|
"""Set up the DHCP websocket API."""
|
||||||
websocket_api.async_register_command(hass, ws_subscribe_discovery)
|
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 _DiscoverySubscription:
|
||||||
"""Class to hold and manage the subscription data."""
|
"""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
|
@callback
|
||||||
def _async_on_discovery(self, service_info: _DhcpServiceInfo) -> None:
|
def _async_on_discovery(self, service_info: _DhcpServiceInfo) -> None:
|
||||||
"""Handle the callback."""
|
"""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
|
@websocket_api.require_admin
|
||||||
|
Loading…
x
Reference in New Issue
Block a user