Skip to content

Commit

Permalink
Adjust handling missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrMachowski committed Jan 5, 2025
1 parent b5ca27d commit 0648a9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hacs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/setup-python@v2
name: Setup Python
with:
python-version: '3.8.x'
python-version: '3.13.x'

- uses: actions/cache@v2
name: Cache
Expand Down
9 changes: 6 additions & 3 deletions custom_components/smartthings_soundbar/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

import requests
from homeassistant.const import (STATE_OFF, STATE_ON, STATE_PAUSED, STATE_PLAYING)
from homeassistant.const import (STATE_OFF, STATE_ON, STATE_PAUSED, STATE_PLAYING, STATE_UNAVAILABLE)

API_BASEURL = "https://api.smartthings.com/v1"
API_DEVICES = API_BASEURL + "/devices/"
Expand Down Expand Up @@ -33,13 +33,16 @@ def device_update(entity):
resp = requests.get(API_DEVICE_STATUS, headers=REQUEST_HEADERS)
data = resp.json()

device_volume = SoundbarApi.extractor(data, "main.volume.value")
device_volume = min(int(device_volume) / entity._max_volume, 1)
switch_state = SoundbarApi.extractor(data, "main.switch.value")
if switch_state is None:
entity._state = STATE_UNAVAILABLE
return
playback_state = SoundbarApi.extractor(data, "main.playbackStatus.value")
device_source = SoundbarApi.extractor(data, "main.inputSource.value")
device_all_sources = json.loads(SoundbarApi.extractor(data, "main.supportedInputSources.value"))
device_muted = SoundbarApi.extractor(data, "main.mute.value") != "unmuted"
device_volume = SoundbarApi.extractor(data, "main.volume.value")
device_volume = min(int(device_volume) / entity._max_volume, 1)

if switch_state == "on":
if device_source.lower() in CONTROLLABLE_SOURCES:
Expand Down

0 comments on commit 0648a9e

Please sign in to comment.