Skip to content

Commit

Permalink
Fix bulk update API endpoint with the invert_value option (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienwarin committed Feb 17, 2024
1 parent 99d3274 commit fe465d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.8.1

- Fix bulk update API endpoint introduced in previous version with the invert_value option for binary sensor introduced in version 3.6.1

## 3.8.0

- Add new API endpoint to push all states at once from the IPX800 (bulk update). See README for more information
Expand Down
5 changes: 3 additions & 2 deletions custom_components/ipx800v4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,13 @@ async def get(self, request, device_type, data):
return web.Response(status=HTTPStatus.UNAUTHORIZED, text="Unauthorized")
hass = request.app["hass"]

_LOGGER.debug("Bulk update %s : %s", device_type, data)
_LOGGER.debug("Bulk update %s from %s : %s", device_type, self.host, data)
for device_config in self.devices:
index = int(device_config[CONF_ID]) - 1
if device_config[CONF_TYPE] == device_type and index >= 0 and index < len(data):
entity_id = ".".join([device_config[CONF_COMPONENT], slugify(device_config[CONF_NAME])])
state = "on" if data[index] in ["1", "on", "true"] else "off"
invert_value = device_config[CONF_INVERT_VALUE] if CONF_INVERT_VALUE in device_config else False
state = "on" if data[index] == ("0" if invert_value else "1") else "off"
old_state = hass.states.get(entity_id)
if old_state:
if state != old_state.state:
Expand Down

0 comments on commit fe465d0

Please sign in to comment.