Skip to content

Commit

Permalink
Merge pull request #72 from albaintor/available_mode
Browse files Browse the repository at this point in the history
Available mode
  • Loading branch information
JackJPowell authored Dec 11, 2024
2 parents 0e370ef + 7110d52 commit 009c8d2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
29 changes: 28 additions & 1 deletion custom_components/unfoldedcircle/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,16 @@ async def async_step_select_entities(
'Using remote ID "%s" to get and set subscribed entities', remote.hostname
)

integration_id = await connect_integration(remote)
# Remote 2 : http://x.x.x.x/configurator#/integrations-devices/hass.main
# Remote 3 : http://x.x.x.x/configurator/#/integration/hass.main
if remote.new_web_configurator:
remote_ha_config_url = (
f"{remote.configuration_url}#/integration/{integration_id}"
)
else:
remote_ha_config_url = f"{remote.configuration_url.rstrip('/')}#/integrations-devices/{integration_id}"

websocket_url = await get_registered_websocket_url(remote)
if websocket_url is None:
websocket_url = get_ha_websocket_url(hass)
Expand Down Expand Up @@ -798,6 +808,7 @@ async def async_step_select_entities(
return config_flow.async_show_menu(
step_id="select_entities",
menu_options=["error", "finish"],
description_placeholders={"remote_ha_config_url": remote_ha_config_url},
)
_LOGGER.debug(
"Found configuration subscription for remote %s (subscription_id %s) : entities %s",
Expand Down Expand Up @@ -857,15 +868,23 @@ async def async_step_select_entities(
data_schema.update({vol.Required("subscribe_entities", default=True): bool})

_LOGGER.debug("Add/removal of entities %s", data_schema)

return config_flow.async_show_form(
step_id="select_entities",
data_schema=vol.Schema(data_schema),
description_placeholders={"remote_name": remote.name},
description_placeholders={
"remote_name": remote.name,
"remote_ha_config_url": remote_ha_config_url,
},
errors=errors,
)

# When the user has selected entities to add/remove as available for the HA driver
if user_input is not None:
integration_id = await connect_integration(
remote, subscribed_entities_subscription.driver_id
)

configure_entities_subscription = websocket_client.get_driver_subscription(
remote.hostname
)
Expand All @@ -879,6 +898,7 @@ async def async_step_select_entities(
return config_flow.async_show_menu(
step_id="select_entities",
menu_options=["error", "finish"],
description_placeholders={"remote_ha_config_url": remote_ha_config_url},
)
subscribed_entities: list[str] = []
if subscribed_entities_subscription:
Expand Down Expand Up @@ -919,6 +939,9 @@ async def async_step_select_entities(
return config_flow.async_show_menu(
step_id="select_entities",
menu_options=["error", "finish"],
description_placeholders={
"remote_ha_config_url": remote_ha_config_url,
},
)

# Entities sent successfully to the HA driver, store the list in the registry
Expand Down Expand Up @@ -951,6 +974,9 @@ async def async_step_select_entities(
return config_flow.async_show_menu(
step_id="select_entities",
menu_options=["error", "finish"],
description_placeholders={
"remote_ha_config_url": remote_ha_config_url,
},
)

except Exception as ex: # pylint: disable=broad-except
Expand All @@ -963,6 +989,7 @@ async def async_step_select_entities(
return config_flow.async_show_menu(
step_id="select_entities",
menu_options=["error", "finish"],
description_placeholders={"remote_ha_config_url": remote_ha_config_url},
)
_LOGGER.debug("Entities registered successfully, finishing config flow")
return await finish_callback(None)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/unfoldedcircle/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"issue_tracker": "https://github.com/JackJPowell/hass-unfoldedcircle/issues",
"requirements": [
"websockets>=12.0,<14",
"pyUnfoldedCircleRemote==0.12.4",
"pyUnfoldedCircleRemote==0.12.5",
"wakeonlan==3.1.0"
],
"version": "0.14.0",
Expand Down
20 changes: 14 additions & 6 deletions custom_components/unfoldedcircle/pyUnfoldedCircleRemote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def __init__(
self._external_entity_configuration_available: bool = False
self._bt_enabled: bool = False
self._wifi_enabled: bool = False
self._new_web_configurator = True

@property
def name(self):
Expand Down Expand Up @@ -455,8 +456,14 @@ def docks(self):

@property
def external_entity_configuration_available(self):
"""Is External entity configuration available"""
return self._external_entity_configuration_available

@property
def new_web_configurator(self):
"""Is remote running new web configurator"""
return self._new_web_configurator

### URL Helpers ###
def validate_url(self, uri):
"""Validate passed in URL and attempts to correct api endpoint if path isn't supplied."""
Expand Down Expand Up @@ -863,10 +870,15 @@ async def get_version(self) -> dict[str]:
core = information.get("core", "")
# We only care about the beginning of the version for this compare
self._external_entity_configuration_available = True
self._new_web_configurator = False
else:
self._sw_version = information.get("os", "")
if Version(self._sw_version) >= Version("2.0.0"):
self._external_entity_configuration_available = True
if Version(self._sw_version) >= Version("2.2.0"):
self._new_web_configurator = True
else:
self._new_web_configurator = False
return information

async def get_remote_wifi_info(self) -> dict[str, any]:
Expand Down Expand Up @@ -971,15 +983,11 @@ async def set_remote_integration_entities(
await self.raise_on_error(response)
return True

async def delete_remote_entity(
self, entity_id: str
) -> bool:
async def delete_remote_entity(self, entity_id: str) -> bool:
"""Delete the given entity ID on the remote."""
async with (
self.client() as session,
session.delete(
self.url(f"entities/{entity_id}")
) as response,
session.delete(self.url(f"entities/{entity_id}")) as response,
):
await self.raise_on_error(response)
return True
Expand Down
6 changes: 4 additions & 2 deletions custom_components/unfoldedcircle/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
}
},
"select_entities": {
"title": "Configure Entities (Optional)",
"title": "Configure Entities",
"description": "Finish [configuration]({remote_ha_config_url}) on your remote",
"data": {
"add_entities": "Entities to share with Remote",
"remove_entities": "Entities to remove from Remote",
Expand All @@ -47,7 +48,7 @@
"pin": "PIN Code",
"ha_ws_url": "Home Assistant Websocket URL"
},
"title": "Remote Two"
"title": "Unfolded Circle Remote"
},
"reauth_confirm": {
"data": {
Expand Down Expand Up @@ -98,6 +99,7 @@
},
"select_entities": {
"title": "Configure Entities",
"description": "Finish [configuration]({remote_ha_config_url}) on your remote after submitting",
"data": {
"add_entities": "Entities to share with Remote",
"remove_entities": "Entities to remove from Remote",
Expand Down
16 changes: 9 additions & 7 deletions custom_components/unfoldedcircle/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,25 @@
}
},
"select_entities": {
"title": "Configure Entities (Optional)",
"title": "Configurer les entités",
"description": "Lien vers la [la configuration]({remote_ha_config_url})",
"data": {
"add_entities": "Entities to share with Remote",
"remove_entities": "Entities to remove from Remote",
"add_entities": "Entités à ajouter à la télécommande",
"remove_entities": "Entités à retirer de la télécommande",
"subscribe_entities": "Activer toutes les entités synchronisées"
},
"menu_options": {
"remote_websocket": "Remote is not connected, try to reconfigure the URL",
"finish": "Ignore this step and finish",
"error": "Unable to communicate with the remote. Retry?"
"remote_websocket": "La télécommande n'est pas connectée, essayez de reconfigurer l'adresse",
"finish": "Ignorer cette étape et terminer",
"error": "Impossible de commmuniquer avec la télécommande. Réessayer ?"
}
},
"zeroconf_confirm": {
"data": {
"pin": "Code PIN",
"ha_ws_url": "Adresse Websocket Home Assistant"
},
"title": "Remote Two"
"title": "Remote Two ou 3"
},
"reauth_confirm": {
"data": {
Expand Down Expand Up @@ -86,6 +87,7 @@
},
"select_entities": {
"title": "Configurer les entités",
"description": "Lien vers la [la configuration]({remote_ha_config_url})",
"data": {
"add_entities": "Entités à ajouter à la télécommande",
"remove_entities": "Entités à retirer de la télécommande",
Expand Down

0 comments on commit 009c8d2

Please sign in to comment.