Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions homeassistant/components/goalzero/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
)
)
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated

CONFIG_SCHEMA = vol.Schema(
{DOMAIN: vol.Schema(vol.All(cv.ensure_list, [GOALZERO_SCHEMA]))},
extra=vol.ALLOW_EXTRA,
)


PLATFORMS = ["binary_sensor"]

Expand All @@ -61,8 +56,6 @@ async def async_setup_entry(hass, entry):
name = entry.data[CONF_NAME]
host = entry.data[CONF_HOST]

_LOGGER.debug("Setting up %s integration with host %s", DOMAIN, host)

session = async_get_clientsession(hass)
api = Yeti(host, hass.loop, session)
try:
Expand All @@ -76,7 +69,6 @@ async def async_update_data():
try:
await api.get_state()
except exceptions.ConnectError as err:
_LOGGER.warning("Failed to update data from Yeti")
raise UpdateFailed(f"Failed to communicating with API: {err}") from err

coordinator = DataUpdateCoordinator(
Expand Down Expand Up @@ -117,10 +109,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
class YetiEntity(CoordinatorEntity):
"""Representation of a Goal Zero Yeti entity."""

def __init__(self, _api, coordinator, name, sensor_name, server_unique_id):
def __init__(self, api, coordinator, name, server_unique_id):
"""Initialize a Goal Zero Yeti entity."""
super().__init__(coordinator)
self.api = _api
self.api = api
self._name = name
self._server_unique_id = server_unique_id
self._device_class = None
Expand Down
7 changes: 3 additions & 4 deletions homeassistant/components/goalzero/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ class YetiBinarySensor(YetiEntity, BinarySensorEntity):

def __init__(self, api, coordinator, name, sensor_name, server_unique_id):
"""Initialize a Goal Zero Yeti sensor."""
super().__init__(api, coordinator, name, sensor_name, server_unique_id)
super().__init__(api, coordinator, name, server_unique_id)

self._condition = sensor_name

variable_info = BINARY_SENSOR_DICT[sensor_name]
self._condition_name = variable_info[0]
self._icon = variable_info[2]
self.api = api
self._device_class = variable_info[1]

@property
Expand All @@ -53,8 +52,8 @@ def unique_id(self):
@property
def is_on(self):
"""Return if the service is on."""
if self.api.data:
return self.api.data[self._condition] == 1
if self.api.data[self._condition] == 1:
return True
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated

@property
def icon(self):
Expand Down
9 changes: 5 additions & 4 deletions homeassistant/components/goalzero/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ async def async_step_user(self, user_input=None):

try:
await self._async_try_connect(host)
return self.async_create_entry(
title=name,
data={CONF_HOST: host, CONF_NAME: name},
)
except exceptions.ConnectError:
errors["base"] = "cannot_connect"
_LOGGER.exception("Error connecting to device at %s", host)
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
Expand All @@ -47,6 +43,11 @@ async def async_step_user(self, user_input=None):
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
return self.async_create_entry(
title=name,
data={CONF_HOST: host, CONF_NAME: name},
)

user_input = user_input or {}
return self.async_show_form(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/goalzero/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_host": "This is not the Yeti you are looking for",
"invalid_host": "Invalid host provided",
"unknown": "Unknown Error"
},
"abort": {
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/goalzero/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"error": {
"cannot_connect": "Failed to connect",
"invalid_host": "This is not the Yeti you are looking for",
"invalid_host": "Invalid host provided",
"unknown": "Unknown Error"
},
"step": {
Expand Down
5 changes: 0 additions & 5 deletions tests/components/goalzero/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ async def test_flow_user(hass):
DOMAIN,
context={"source": SOURCE_USER},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "user"
assert result["errors"] == {}
_flow_next(hass, result["flow_id"])

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input=CONF_CONFIG_FLOW,
Expand Down