Skip to content

Commit

Permalink
enhance config-flow logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sehaas committed May 9, 2022
1 parent 8e806db commit f40e7f9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions custom_components/hisense_tv/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async def _async_authcode_response(self, message):
)

def _unsubscribe(self):
_LOGGER.debug("_unsubscribe")
if self._unsubscribe_auth is not None:
self._unsubscribe_auth()
self._unsubscribe_auth = None
Expand All @@ -76,14 +77,16 @@ def _unsubscribe(self):

async def async_step_user(self, user_input=None) -> FlowResult:
if self.task_auth is True:
_LOGGER.debug("async_step_user - task_auth is True")
return self.async_show_progress_done(next_step_id="finish")

if self.task_auth is False:
self.task_auth = None
_LOGGER.debug("async_step_user - task_auth is False")
return self.async_show_progress_done(next_step_id="auth")

if user_input is None:
_LOGGER.debug("async_step_user INFO None")
_LOGGER.debug("async_step_user - user_input is None")
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
Expand All @@ -97,7 +100,7 @@ async def async_step_user(self, user_input=None) -> FlowResult:
),
)

_LOGGER.debug("async_step_user NOT task_mqtt")
_LOGGER.debug("async_step_user - set task_mqtt")
self.task_mqtt = {
CONF_MAC: user_input.get(CONF_MAC),
CONF_NAME: user_input.get(CONF_NAME),
Expand Down Expand Up @@ -126,12 +129,14 @@ async def _check_authentication(self, client_id):
% (self.task_mqtt.get(CONF_MQTT_IN), client_id),
msg_callback=self._async_pin_not_needed,
)
_LOGGER.debug("_check_authentication - publish gettvstate")
mqtt.publish(
hass=self.hass,
topic="%s/remoteapp/tv/ui_service/%s/actions/gettvstate"
% (self.task_mqtt.get(CONF_MQTT_OUT), client_id),
payload="",
)
_LOGGER.debug("_check_authentication - publish sourcelist")
mqtt.publish(
hass=self.hass,
topic="%s/remoteapp/tv/ui_service/%s/actions/sourcelist"
Expand All @@ -141,22 +146,23 @@ async def _check_authentication(self, client_id):

async def async_step_reauth(self, user_input=None):
"""Reauth handler."""
_LOGGER.debug("async_step_reauth: %s", user_input)
self.task_auth = None
return await self.async_step_auth(user_input=user_input)

async def async_step_auth(self, user_input=None):
"""Auth handler."""
if self.task_auth is True:
_LOGGER.debug("async_step_auth finish")
_LOGGER.debug("async_step_auth - task_auth is True -> finish")
return self.async_show_progress_done(next_step_id="finish")

if self.task_auth is False:
_LOGGER.debug("async_step_auth reauth")
_LOGGER.debug("async_step_auth - task_auth is False -> reauth")
return self.async_show_progress_done(next_step_id="reauth")

if user_input is None:
self.task_auth = None
_LOGGER.debug("async_step_auth show form")
_LOGGER.debug("async_step_auth - user_input is None -> show form")
return self.async_show_form(
step_id="auth",
data_schema=vol.Schema(
Expand All @@ -166,7 +172,7 @@ async def async_step_auth(self, user_input=None):
),
)
else:
_LOGGER.debug("async_step_auth send authentication")
_LOGGER.debug("async_step_auth send authentication: %s", user_input)
client_id = DEFAULT_CLIENT_ID
self._unsubscribe_auth = await mqtt.async_subscribe(
hass=self.hass,
Expand Down

0 comments on commit f40e7f9

Please # to comment.