Git Product home page Git Product logo

python-temescal's Introduction

Python control for LG speaker systems

A simple Python API for controlling speakers from LG that can otherwise be controlled via the LG wifi speaker app.

Example use

Device discovery is out of scope of this project. Use an mdns module such as netdisco to locate devices on your network.

Connect to a speaker at 192.168.1.15

import temescal

speaker = temescal.temescal("192.168.1.15")

Connect with a registered callback:

import temescal

speaker = temescal.temescal("192.168.1.15", callback=speaker_callback)

The callback will be called whenever Temescal receives a packet from the speaker. This may be a response to a sent command or a gratuitous status update triggered by another control event.

Get the current equaliser state:

import temescal

speaker = temescal.temescal("192.168.1.15", callback=speaker_callback)
speaker.get_eq()

The callback routine will be called with the response.

Set the volume to 20:

import temescal

speaker = temescal.temescal("192.168.1.15", callback=speaker_callback)
speaker.set_volume(20)

This is not an officially supported Google project.

python-temescal's People

Contributors

bernimoses avatar mjg59 avatar teldri avatar tomasrollo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

python-temescal's Issues

Thoughts about socket connection life cycle

This are just some thoughts about the socket connection life cycle. It would be nice to get some feedback. ;)

Currently every time the connection gets closed (ir remote, tcp timeout) we try to reopen it immediately. This causes (at least for me) to wake up the soundbar from standby. I found that if i turn the soundbar off via the ir remote it closes the tcp connection which in turn would immediately turn it back on (as of version 0.2). Edit: Not opening a connection turns it back on but sending data. This is just from my observations and i have to confirm if this is always the case.

For my use case (homeassistant, hass) this is even more pronounced since the current hass component uses polling. Since a already open socket would update the components state itself, i tried to disable the polling. But this caused (as of version 0.1) the connection to drop completely which makes the hass entity kinda like a "zombie process". I'm not going into more detail here since this is mostly hass related and there need to be changes made to the hass component to implement proper uuid handling.

Ok, now my proposal. Instead of reopening the connection after receiving the null byte we close the client socket. Edit: It seems that this part is not needed since only sending data would turn the soundbar back on. If any library method is called afterwards we reopen the socket connection (if it is closed). This means that we don't get status updates if the soundbar is turned on (wake up from standby) from outside (ir remote, other socket connection) but in turn we allow it to go to sleep.

For the hass part this would mean we use the zeroconf announce (the soundbar sends on broadcast/start) to create the entity and reopen the socket on the same event to get the current status. Maybe zeroconf would also be interesting to implement here in case we get a announce for "wake up from standby" (didn't check yet).

Is there a part of this you would consider adding to this library in one or another (pull request) way?

New equalizer setting

I´ve been playing around with this library and a "LG SL10YG" soundbar.
Seems like LG added another equalizer setting, setting number 18.
In the LG soundbar app it´s called "DTS:X" (not to confuse with "DTS Virtual:X" ...)

equalisers = ["Standard", "Bass", "Flat", "Boost", "Treble and Bass", "User", "Music", "Cinema", "Night", "News", "Voice", "ia_sound", "Adaptive Sound Control", "Movie", "Bass Blast", "Dolby Atmos", "DTS Virtual X", "Bass Boost Plus"]

should be extended to something like that:

equalisers = ["Standard", "Bass", "Flat", "Boost", "Treble and Bass", "User", "Music", "Cinema", "Night", "News", "Voice", "ia_sound", "Adaptive Sound Control", "Movie", "Bass Blast", "Dolby Atmos", "DTS Virtual X", "Bass Boost Plus", "DTS X"]

Would have made a quick pull request but reading and creating that CLA whatever something stopped me.

Would be nice to see that new equalizer setting implemented.

`response` is never `None`

I am trying to get this to work with my sound bar, and I am getting a JSONDecodeError. I believe the response I am getting is blank, but it is attempted to be decoded.
The response as returned from decrypt_packet will never be None, though it seems that it can be blank.

I don't have a good way to test this right now, but it might be sufficient to do:

if response:
    self.callback(json.loads(response))

Thanks for this, and I hope I can get it working for me.

Add a option to "SETTING_VIEW_INFO": "Night Time"

Night Mode and Night Time are not the same thing. My Soundbar SP9YA doesn't have Night Mode, but it has Night Time.

Example json from getting the SETTING_VIEW_INFO:

{
"result": "ok",
"cmd": "notibyget",
"msg": "SETTING_VIEW_INFO",
"data": {
"i_av_sync": 0,
"i_center_min": -6,
"b_auto_power": true,
"b_tv_remote": true,
"b_night_time": false,
"b_enable_dialog": false,
"b_drc": false,
"b_auto_vol": false,
"b_soundbarmode": false,
"i_dialog_max": 6,
"b_rear": false,
"b_support_diag": true,
"i_woofer_level": 9,
"i_side_max": 6,
"b_set_device_name": false,
"b_neuralx": false,
"b_support_avsmrm": true,
"b_avsmrm_status": false,
"i_center_max": 6,
"i_top_min": -6,
"b_wow_connect": false,
"s_ipv4_addr": "[ip address]",
"b_nighttime_enable": true,
"i_woofer_min": -15,
"i_woofer_max": 6,
"i_dialog_level": 0,
"i_rear_level": 6,
"i_rear_min": -6,
"i_rear_max": 6,
"i_top_level": 6,
"i_top_max": 6,
"i_center_level": 7,
"i_side_level": 6,
"i_side_min": -6,
"i_dialog_min": 0,
"i_curr_eq": 0,
"i_calibration_status": 0,
"s_user_name": "[user name]",
"s_ipv6_addr": "[ip address]"
}
}

Packet to set Night Time true: (works on my machine and SP9YA)

{"cmd": "set", "data": {"b_night_time": True}, "msg": "SETTING_VIEW_INFO"}

Update for new SoundBar LG 2020

Hello,

I've come here because of the famous HA bug with LG soundbars, in particular the last few years. 2019-2021

I have been testing your code independently and I found that my soundbar: SN9YG has a new identifier for the list of equalisers.
Would it be possible to extend it and add it to a HA update?
I am attaching the code where you can see the identifier 19, which is not included in the code.

Would it be possible?

`
[DEBUG ON]

def speaker_callback(response):
"""Handle responses from the speakers."""
data = response["data"]
print(data)

[DEBUG ON]

speaker = temescal.temescal("192.168.1.79", callback=speaker_callback)
[DEBUG ON]
speaker.get_eq()
{'ai_eq_list': [19, 14, 0, 13, 6, 5, 15], 'i_curr_eq': 13, 'i_bass': 5, 'i_treble': 5}
[DEBUG ON]

`

Is it possible to make this work with LG DS90xx Soundbar

Hi!

I know this is quite outdated, but i wonder if this can be made to work with LG SB90QY and other newer LG Soundbars.

All i get is a

ConnectionRefusedError: [WinError 10061] Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte

The target computer denied the connection attempt.

Ideas? Hints?

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.