Skip to content

Commit

Permalink
Member-requested changes (part 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed Oct 12, 2018
1 parent fe7704a commit 851ff3f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/openuv.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def unique_id(self) -> str:
async def async_added_to_hass(self):
"""Register callbacks."""
@callback
def update(self):
def update():
"""Update the state."""
self.async_schedule_update_ha_state(True)

Expand Down
11 changes: 6 additions & 5 deletions homeassistant/components/openuv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def async_setup(hass, config):
if identifier in configured_instances(hass):
return True

hass.async_add_job(
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={'source': SOURCE_IMPORT},
Expand Down Expand Up @@ -154,6 +154,7 @@ async def async_setup_entry(hass, config_entry):
await openuv.async_update()
hass.data[DOMAIN][DATA_OPENUV_CLIENT][config_entry.entry_id] = openuv
except OpenUvError as err:
_LOGGER.error('Config entry failed: %s', err)
raise ConfigEntryNotReady

for component in ('binary_sensor', 'sensor'):
Expand All @@ -177,15 +178,15 @@ async def refresh(event_time):

async def async_unload_entry(hass, config_entry):
"""Unload an OpenUV config entry."""
for component in ('binary_sensor', 'sensor'):
await hass.config_entries.async_forward_entry_unload(
config_entry, component)

hass.data[DOMAIN][DATA_OPENUV_CLIENT].pop(config_entry.entry_id)

remove_listener = hass.data[DOMAIN][DATA_OPENUV_LISTENER].pop(
config_entry.entry_id)
remove_listener()

for component in ('binary_sensor', 'sensor'):
await hass.config_entries.async_forward_entry_unload(
config_entry, component)

return True

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/openuv/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def async_step_user(self, user_input=None):

identifier = '{0}, {1}'.format(latitude, longitude)
if identifier in configured_instances(self.hass):
return await self._show_form({'base': 'identifier_exists'})
return await self._show_form({CONF_LATITUDE: 'identifier_exists'})

websession = aiohttp_client.async_get_clientsession(self.hass)
api_key_validation = await validate_api_key(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/openuv.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def unit_of_measurement(self):
async def async_added_to_hass(self):
"""Register callbacks."""
@callback
def update(self):
def update():
"""Update the state."""
self.async_schedule_update_ha_state(True)

Expand Down
4 changes: 2 additions & 2 deletions tests/components/openuv/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def test_duplicate_error(hass):
flow.hass = hass

result = await flow.async_step_user(user_input=conf)
assert result['errors'] == {'base': 'identifier_exists'}
assert result['errors'] == {CONF_LATITUDE: 'identifier_exists'}


async def test_invalid_api_key(hass):
Expand All @@ -43,7 +43,7 @@ async def test_invalid_api_key(hass):
with patch('pyopenuv.util.validate_api_key',
return_value=mock_coro(False)):
result = await flow.async_step_user(user_input=conf)
assert result['errors'] == {'base': 'invalid_api_key'}
assert result['errors'] == {CONF_API_KEY: 'invalid_api_key'}


async def test_show_form(hass):
Expand Down

0 comments on commit 851ff3f

Please sign in to comment.