Skip to content

Commit

Permalink
Showing 4 changed files with 67 additions and 59 deletions.
86 changes: 47 additions & 39 deletions custom_components/saleryd_ftx/config_flow.py
Original file line number Diff line number Diff line change
@@ -54,13 +54,8 @@ async def async_step_user(self, user_input=None):

return await self._show_config_form(user_input)

@staticmethod
@callback
def async_get_options_flow(config_entry):
return SalerydLokeOptionsFlowHandler(config_entry)

async def _show_config_form(self, user_input): # pylint: disable=unused-argument
"""Show the configuration form to edit location data."""
"""Show the configuration form to edit configuration data."""
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
@@ -92,39 +87,52 @@ async def _test_connection(self, ip, port):
return True
except Exception as e: # pylint: disable=broad-except
pass
return False


class SalerydLokeOptionsFlowHandler(config_entries.OptionsFlow):
"""SalerydLoke config flow options handler."""

def __init__(self, config_entry):
"""Initialize HACS options flow."""
self.config_entry = config_entry
self.options = dict(config_entry.options)

async def async_step_init(self, user_input=None): # pylint: disable=unused-argument
"""Manage the options."""
return await self.async_step_user()

async def async_step_user(self, user_input=None):
"""Handle a flow initialized by the user."""
if user_input is not None:
self.options.update(user_input)
return await self._update_options()
return False

return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
vol.Required(x, default=self.options.get(x, True)): bool
for x in sorted(PLATFORMS)
}
),
)

async def _update_options(self):
"""Update config entry options."""
return self.async_create_entry(
title=self.config_entry.data.get(CONF_NAME), data=self.options
)
# @staticmethod
# @callback
# def async_get_options_flow(config_entry):
# return SalerydLokeOptionsFlowHandler(config_entry)


# class SalerydLokeOptionsFlowHandler(config_entries.OptionsFlow):
# """SalerydLoke config flow options handler."""

# def __init__(self, config_entry):
# self.config_entry = config_entry

# async def async_step_init(self, user_input=None): # pylint: disable=unused-argument
# """Manage the options."""
# return await self.async_step_user()

# async def async_step_user(self, user_input=None):
# """Handle a flow initialized by the user."""
# errors: Dict[str, str] = {}

# if user_input is not None:
# if not errors:
# return self.async_create_entry(title="", data=user_input)

# return self.async_show_form(
# step_id="user",
# data_schema=vol.Schema(
# {
# vol.Required(
# CONF_WEBSOCKET_IP,
# default=self.config_entry.data.get(CONF_WEBSOCKET_IP),
# ): str,
# vol.Required(
# CONF_WEBSOCKET_PORT,
# default=self.config_entry.data.get(CONF_WEBSOCKET_PORT),
# ): int,
# }
# ),
# # data_schema=vol.Schema(
# # {
# # vol.Required(x, default=self.options.get(x, True)): bool
# # for x in sorted(PLATFORMS)
# # }
# # ),
# )
15 changes: 8 additions & 7 deletions custom_components/saleryd_ftx/strings.json
Original file line number Diff line number Diff line change
@@ -2,16 +2,17 @@
"config": {
"step": {
"user": {
"title": "SalerydLoke",
"description": "If you need help with the configuration have a look here: https://github.com/custom-components/integration_blueprint",
"title": "Saleryd FTX",
"description": "Follow instructions in manual to connect FTX to local network. Enter connections details below. If you need help with the configuration have a look here: https://github.com/bj00rn/ha-saleryd-ftx",
"data": {
"websocket_ip": "Websocket URL",
"name": "Name",
"websocket_ip": "Websocket Ip adress for the FTX web interface, ie 192.168.1.151",
"websocket_port": "Port"
}
}
},
"error": {
"auth": "URL/Port is wrong"
"auth": "Could not connect. Maybe Websocket URL/Port is wrong?"
},
"abort": {
"single_instance_allowed": "Only a single instance is allowed."
@@ -21,9 +22,9 @@
"step": {
"user": {
"data": {
"binary_sensor": "Binary sensor enabled",
"sensor": "Sensor enabled",
"switch": "Switch enabled"
"name": "Name",
"websocket_ip": "Websocket Ip adress for the FTX web interface, ie 192.168.1.151",
"websocket_port": "Websocket port."
}
}
}
19 changes: 9 additions & 10 deletions custom_components/saleryd_ftx/translations/en.json
Original file line number Diff line number Diff line change
@@ -2,16 +2,17 @@
"config": {
"step": {
"user": {
"title": "Saleryd Loke FTX integration",
"description": "Provide websocket url to FTX fan",
"websocket": "Websocket URL",
"title": "Saleryd FTX",
"description": "Follow instructions in manual to connect FTX to local network. Enter connections details below. If you need help with the configuration have a look here: https://github.com/bj00rn/ha-saleryd-ftx",
"data": {
"websocket": "Websocket URL"
"name": "Name",
"websocket_ip": "Websocket Ip adress for the FTX web interface, ie 192.168.1.151",
"websocket_port": "Port"
}
}
},
"error": {
"connect": "Error getting data, Wrong websocket url?"
"auth": "Could not connect. Maybe Websocket URL/Port is wrong?"
},
"abort": {
"single_instance_allowed": "Only a single instance is allowed."
@@ -20,13 +21,11 @@
"options": {
"step": {
"user": {
"websocket": "Websocket URL",
"data": {
"websocket": "Websocket URL"
"name": "Name",
"websocket_ip": "Websocket Ip adress for the FTX web interface, ie 192.168.1.151",
"websocket_port": "Websocket port."
}
},
"error": {
"connect": "Error getting data, Wrong websocket url?"
}
}
}
6 changes: 3 additions & 3 deletions custom_components/saleryd_ftx/websocket.py
Original file line number Diff line number Diff line change
@@ -159,9 +159,9 @@ async def send_message(self, message):
url = f"http://{self.host}:{self.port}"
try:
async with self.session.ws_connect(url) as ws:
LOGGER.debug("Sending message to FTX %s", message)
await ws.send_str(message)
return True
return True
except Exception as e:
LOGGER.error("Failed to send message %s", message, exc_info=True)

return False
raise Exception from e

0 comments on commit 7bd08ee

Please sign in to comment.