hotfix for mac-detection and various variable names (#139)
* Change Client-Name: The client name inside LVA is not capable of having spaces in the name. Fixed the example. * Add first version of Docker-Compose for developers * Add variable for network-interface and auto detection by default * Added autodetection for the MAC-Address based on the detected or specified network-interface. * Switched from listening on all IP-Addresses to the IP of the default interface, usually u set the correct network-interface and it will automatically detect the right IP-Address. * Added missing variables, fixed variables names * Fixed not working variables for example sound-files. * Moved the auto-name creation from shell to python. The name is no longer mandatory, it will be generated if no name is given.
This commit is contained in:
1 parent
f72e5c8d30
commit
4052daae01
11 files changed
+256
-113
No files matched your search
@@ -18,20 +18,13 @@ MDNS_TARGET_IP = "224.0.0.251"
|
||||
|
||||
class HomeAssistantZeroconf:
|
||||
def __init__(
|
||||
self, port: int, name: Optional[str] = None, host: Optional[str] = None
|
||||
self, port: int, mac_address: str, host_ip_address: str, name: Optional[str] = None, host: Optional[str] = None
|
||||
) -> None:
|
||||
self.port = port
|
||||
self.name = name or _get_mac_address()
|
||||
self.mac_address = mac_address
|
||||
self.name = name or self.mac_address
|
||||
self.host_ip_address = host_ip_address
|
||||
|
||||
if not host:
|
||||
test_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
test_sock.setblocking(False)
|
||||
test_sock.connect((MDNS_TARGET_IP, 1))
|
||||
host = test_sock.getsockname()[0]
|
||||
_LOGGER.debug("Detected IP: %s", host)
|
||||
|
||||
assert host
|
||||
self.host = host
|
||||
self._aiozc = AsyncZeroconf()
|
||||
|
||||
async def register_server(self) -> None:
|
||||
@@ -39,11 +32,11 @@ class HomeAssistantZeroconf:
|
||||
service_info = AsyncServiceInfo(
|
||||
"_esphomelib._tcp.local.",
|
||||
f"{self.name}._esphomelib._tcp.local.",
|
||||
addresses=[socket.inet_aton(self.host)],
|
||||
addresses=[socket.inet_aton(self.host_ip_address)],
|
||||
port=self.port,
|
||||
properties={
|
||||
"version": "2025.9.0",
|
||||
"mac": _get_mac_address(),
|
||||
"mac": self.mac_address,
|
||||
"board": "host",
|
||||
"platform": "HOST",
|
||||
"network": "ethernet", # or "wifi"
|
||||
@@ -53,12 +46,3 @@ class HomeAssistantZeroconf:
|
||||
await self._aiozc.async_register_service(service_info)
|
||||
_LOGGER.debug("Zeroconf discovery enabled: %s", service_info)
|
||||
|
||||
|
||||
def _get_mac_address() -> str:
|
||||
"""Return MAC address formatted as hex with no colons."""
|
||||
return "".join(
|
||||
# pylint: disable=consider-using-f-string
|
||||
["{:02x}".format((uuid.getnode() >> ele) & 0xFF) for ele in range(0, 8 * 6, 8)][
|
||||
::-1
|
||||
]
|
||||
)
|
||||
Reference in new issue
Block a user