Skip to content

Commit

Permalink
fix: Could not use with domain name instead of IP
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Aug 6, 2024
1 parent 3330f82 commit a507d21
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions custom_components/solarman/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import socket
import logging

from ipaddress import IPv4Address
from ipaddress import IPv4Address, AddressValueError

from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -36,7 +37,12 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
lookup_path = hass.config.path(LOOKUP_DIRECTORY_PATH)
lookup_file = options.get(CONF_LOOKUP_FILE)

if IPv4Address(inverter_host).is_private:
try:
ipaddr = IPv4Address(inverter_host)
except AddressValueError:
ipaddr = IPv4Address(socket.gethostbyname(inverter_host))

if ipaddr.is_private:
inverter_discovery = InverterDiscovery(hass, inverter_host)
if discovery:
await inverter_discovery.discover()
Expand Down

0 comments on commit a507d21

Please sign in to comment.