Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
Fix using wrong method for accessing discovery data (#69)
Browse files Browse the repository at this point in the history
* Fix using wrong method for accessing discovery data

* Add import for zeroconf
  • Loading branch information
DCSBL authored Dec 12, 2021
1 parent 5651596 commit b34d57e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions custom_components/homewizard_energy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from voluptuous.util import Lower

from homeassistant import config_entries
from homeassistant.components import zeroconf
from homeassistant.const import CONF_HOST, CONF_IP_ADDRESS, CONF_PORT
from homeassistant.data_entry_flow import FlowResult

Expand Down Expand Up @@ -53,32 +54,33 @@ async def async_step_user(

return await self.async_step_check(entry_info)

async def async_step_zeroconf(self, discovery_info):
async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle zeroconf discovery."""

_LOGGER.debug("config_flow async_step_zeroconf")

# Validate doscovery entry
if (
"host" not in discovery_info
or "api_enabled" not in discovery_info["properties"]
or "path" not in discovery_info["properties"]
or "product_name" not in discovery_info["properties"]
or "product_type" not in discovery_info["properties"]
or "serial" not in discovery_info["properties"]
"api_enabled" not in discovery_info.properties
or "path" not in discovery_info.properties
or "product_name" not in discovery_info.properties
or "product_type" not in discovery_info.properties
or "serial" not in discovery_info.properties
):
return self.async_abort(reason="invalid_discovery_parameters")

if (discovery_info["properties"]["path"]) != "/api/v1":
if (discovery_info.properties["path"]) != "/api/v1":
return self.async_abort(reason="unsupported_api_version")

if (discovery_info["properties"]["api_enabled"]) != "1":
if (discovery_info.properties["api_enabled"]) != "1":
return self.async_abort(reason="api_not_enabled")

# Pass parameters
entry_info = {
CONF_IP_ADDRESS: discovery_info["host"],
CONF_PORT: discovery_info["port"],
CONF_IP_ADDRESS: discovery_info.host,
CONF_PORT: discovery_info.port,
}

return await self.async_step_check(entry_info)
Expand Down

0 comments on commit b34d57e

Please sign in to comment.