Skip to content

Commit

Permalink
v2.3.13 (#936)
Browse files Browse the repository at this point in the history
* Fix preferred_bitrate for bitrate topic #929

* prevent exception if empty dictionary payload

* changelog
  • Loading branch information
mrlt8 authored Jul 25, 2023
1 parent 967743a commit f70840c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ You can then use the web interface at `http://localhost:5000` where localhost is

See [basic usage](#basic-usage) for additional information or visit the [wiki page](https://github.com/mrlt8/docker-wyze-bridge/wiki/Home-Assistant) for additional information on using the bridge as a Home Assistant Add-on.

## What's Changed in v2.3.13

FIXES:
* Errors when SET/GET `bitrate`. Thanks @plat2on1! (#929)
* Prevent exception on empty GET/SET payload.

## What's Changed in v2.3.12

* NEW:
Expand Down
6 changes: 6 additions & 0 deletions app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## What's Changed in v2.3.13

FIXES:
* Errors when SET/GET `bitrate`. Thanks @plat2on1! (#929)
* Prevent exception on empty GET/SET payload.

## What's Changed in v2.3.12

* NEW:
Expand Down
15 changes: 11 additions & 4 deletions app/wyzebridge/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,24 @@ def _on_message(client, callback, msg):

cam, topic, action = msg_topic[-3:]
include_payload = action == "set" or topic in GET_PAYLOAD
resp = callback(cam, topic, parse_payload(msg) if include_payload else "")
if resp.get("status") != "success":
logger.info(f"[MQTT] {resp}")


def parse_payload(msg):
payload = msg.payload.decode()

with contextlib.suppress(json.JSONDecodeError):
json_msg = json.loads(payload)
if not isinstance(json_msg, (dict, list)):
raise json.JSONDecodeError("NOT json", payload, 0)
payload = json_msg if len(json_msg) > 1 else next(iter(json_msg.values()))

resp = callback(cam, topic, payload if include_payload else "")
if resp.get("status") != "success":
logger.info(f"[MQTT] {resp}")
payload = json_msg or ""
if isinstance(json_msg, dict) and len(json_msg) == 1:
payload = next(iter(json_msg.values()))

return payload


def get_entities(base_topic: str, pan_cam: bool = False, rtsp: bool = False) -> dict:
Expand Down
6 changes: 3 additions & 3 deletions app/wyzebridge/wyze_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def send_tutk_msg(sess: WyzeIOTCSession, cmd: tuple | str, log: str = "info") ->
mux.send_ioctl(bitrate)
res = update_mqtt_values(topic, sess.camera.name_uri, res)
params = None if isinstance(res, int) else params
if topic == "bitrate" and payload:
if tutk_topic == "K10052SetBitrate" and payload:
sess.preferred_bitrate = int(payload)
if isinstance(res, bytes):
res = ",".join(map(str, res))
Expand Down Expand Up @@ -284,8 +284,8 @@ def bitrate_check(res: dict, preferred_bitrate: int):
Returns:
- tutk_protocol.K10052SetBitrate: if bitrate does not match.
"""
if (bitrate := res.get("3")) and bitrate != preferred_bitrate:
logger.debug(f"Wrong {bitrate=} does not match {preferred_bitrate}")
if (bitrate := res.get("3")) and int(bitrate) != preferred_bitrate:
logger.info(f"Wrong {bitrate=} does not match {preferred_bitrate}")

return tutk_protocol.K10052SetBitrate(preferred_bitrate)

Expand Down

0 comments on commit f70840c

Please sign in to comment.