Skip to content

Commit

Permalink
fix global refresh push
Browse files Browse the repository at this point in the history
  • Loading branch information
Aohzan committed Aug 31, 2022
1 parent 2aeaa6e commit 89a3ae4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.2.0

- Fix global refresh from push. Update your PUSH URL to: `/api/ipx800v5_refresh/on`

## 1.1.0

- No diag sensor anymore, set `diag_sensors` to `True` in yaml config to add them
Expand Down
2 changes: 1 addition & 1 deletion README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ipx800v5:
### Demande d'actualisation des états
En faisant un appel PUSH depuis l'IPX sur l'URL `/api/ipx800v5_refresh/`, vous demandez à Home-Assistant de rafraichir l'état de toutes les entités.
En faisant un appel PUSH depuis l'IPX sur l'URL `/api/ipx800v5_refresh/on`, vous demandez à Home-Assistant de rafraichir l'état de toutes les entités.

### Poussez l'état d'une entité

Expand Down
2 changes: 1 addition & 1 deletion custom_components/ipx800v5/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"dependencies": ["http"],
"config_flow": true,
"codeowners": ["@Aohzan"],
"version": "1.1.0",
"version": "1.2.0",
"iot_class": "local_polling"
}
10 changes: 8 additions & 2 deletions custom_components/ipx800v5/request_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ def __init__(self, host: str, password: str) -> None:
async def get(self, request, entity_id, state):
"""Respond to requests from the device."""
if check_api_auth(request, self.host, self.password):
_LOGGER.debug("State update pushed from IPX")
hass = request.app["hass"]
old_state = hass.states.get(entity_id)
_LOGGER.debug("Update %s to state %s", entity_id, state)
if old_state:
hass.states.async_set(entity_id, state, old_state.attributes)
return web.Response(status=HTTPStatus.OK, text="OK")
_LOGGER.warning("Entity not found for state updating: %s", entity_id)
_LOGGER.warning("Authentication for PUSH invalid")


class IpxRequestDataView(HomeAssistantView):
Expand All @@ -74,6 +76,7 @@ def __init__(self, host: str, password: str) -> None:
async def get(self, request, data):
"""Respond to requests from the device."""
if check_api_auth(request, self.host, self.password):
_LOGGER.debug("State update pushed from IPX")
hass = request.app["hass"]
entities_data = data.split("&")
for entity_data in entities_data:
Expand All @@ -92,13 +95,14 @@ async def get(self, request, data):
)

return web.Response(status=HTTPStatus.OK, text="OK")
_LOGGER.warning("Authentication for PUSH invalid")


class IpxRequestRefreshView(HomeAssistantView):
"""Provide a page for the device to call for send multiple data at once."""

requires_auth = False
url = "/api/ipx800v5_refresh"
url = "/api/ipx800v5_refresh/{data}"
name = "api:ipx800v5_refresh"

def __init__(
Expand All @@ -113,8 +117,10 @@ def __init__(
async def get(self, request, data):
"""Respond to requests from the device."""
if check_api_auth(request, self.host, self.password):
self.coordinator.async_request_refresh()
_LOGGER.debug("Update asked from IPX PUSH")
await self.coordinator.async_request_refresh()
return web.Response(status=HTTPStatus.OK, text="OK")
_LOGGER.warning("Authentication for PUSH invalid")


class ApiCallNotAuthorized(BaseException):
Expand Down

0 comments on commit 89a3ae4

Please sign in to comment.