Skip to content

Commit

Permalink
[ 1.0.9 ] - Allow user to disable websocket notifications if desired …
Browse files Browse the repository at this point in the history
…when device is added. This will enable device polling every 10 seconds from Home Assistant UI for status updates.
  • Loading branch information
thlucas1 committed Nov 7, 2023
1 parent c3edeba commit 532b7c3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Change are listed in reverse chronological order (newest to oldest).

<span class="changelog">

###### [ 1.0.9 ] - 2023/11/06

* Allow user to disable websocket notifications if desired when device is added. This will enable device polling every 10 seconds from Home Assistant UI for status updates.

###### [ 1.0.8 ] - 2023/11/05

* Updated config flow to allow configuration key name changes. Updates were failing due to a configuration key name change.
Expand Down
7 changes: 6 additions & 1 deletion custom_components/soundtouchplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,12 @@ async def async_setup_entry(hass:HomeAssistant, entry:ConfigEntry) -> bool:
# get device capabilities - must have IsWebSocketApiProxyCapable=True
# in order to support notifications.
capabilities:Capabilities = await hass.async_add_executor_job(client.GetCapabilities)
if capabilities.IsWebSocketApiProxyCapable:
if (port_websocket == 0):

# SoundTouch device websocket notifications were disabled by user - device will be polled.
_logsi.LogMessage("Component async_setup_entry - device websocket notifications were disabled by the user; polling will be enabled (%s)" % (host))

elif (capabilities.IsWebSocketApiProxyCapable == True):

_logsi.LogVerbose("Component async_setup_entry has verified device is capable of websocket notifications (%s)" % (host))

Expand Down
2 changes: 1 addition & 1 deletion custom_components/soundtouchplus/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _show_user_form(self, errors=None):
{
vol.Required(CONF_HOST, default=self._host): str,
vol.Required(CONF_PORT, default=default_port): cv.port,
vol.Required(CONF_PORT_WEBSOCKET, default=default_port_websocket): cv.port,
vol.Required(CONF_PORT_WEBSOCKET, default=default_port_websocket): vol.All(vol.Coerce(int), vol.Range(min=0, max=65535)),
vol.Required(CONF_PING_WEBSOCKET_INTERVAL, default=default_ping_websocket_interval): vol.All(vol.Coerce(int), vol.Range(min=0, max=3600)),
}
)
Expand Down
5 changes: 2 additions & 3 deletions custom_components/soundtouchplus/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def __init__(self, initParms:EntityInitParms) -> None:

# we will (by default) set polling to false, as the SoundTouch device should be
# sending us updates as they happen if it supports websocket notificationss.
# if not, then we will reset this flag in the __init__ method.
self._attr_should_poll = False

# if websockets are not supported, then we need to enable device polling.
Expand Down Expand Up @@ -452,8 +451,8 @@ def update(self) -> None:
self._zone = self._client.GetZoneStatus(self._attr_should_poll)

# does this device support websocket notifications?
# note - if socket is None, it denotes that websocket notifications are
# NOT supported for the device, and we should not try to restart.
# note - if socket is None, it denotes that websocket notifications are NOT
# supported for the device (or are disabled), and we should not try to restart.
if self._socket is not None:

# is polling enabled? if so it should NOT be since websockets are supported.
Expand Down
2 changes: 1 addition & 1 deletion custom_components/soundtouchplus/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"data_description": {
"host": "Ip address or DNS alias of the device",
"port": "Bose WebServices API Port of the device (default is 8090)",
"port_websocket": "Bose WebSocket API Port of the device (default is 8080)",
"port_websocket": "Bose WebSocket API Port of the device; specify 0 to disable, or range of 1-65535, default is 8080. If disabled, device is polled by HA UI every 10 seconds.",
"ping_websocket_interval": "Bose WebSocket API Ping interval (in seconds) used to keep the connection alive; specify 0 to disable, or range of 30-3600, default is 300"
}
},
Expand Down
2 changes: 1 addition & 1 deletion custom_components/soundtouchplus/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"data_description": {
"host": "Ip address or DNS alias of the device",
"port": "Bose WebServices API Port of the device (default is 8090)",
"port_websocket": "Bose WebSocket API Port of the device (default is 8080)",
"port_websocket": "Bose WebSocket API Port of the device; specify 0 to disable, or range of 1-65535, default is 8080. If disabled, device is polled by HA UI every 10 seconds.",
"ping_websocket_interval": "Bose WebSocket API Ping interval (in seconds) used to keep the connection alive; specify 0 to disable, or range of 30-3600, default is 300"
}
},
Expand Down

0 comments on commit 532b7c3

Please sign in to comment.