API

class hisensetv.HisenseTv(hostname, *, port=36669, username='hisenseservice', password='multimqttservice', timeout=10.0, enable_client_logger=False, ssl_context=None)

Hisense TV.

Parameters
  • hostname (str) – TV hostname or IP.

  • port (int) – Port of the MQTT broker on the TV, typically 36669.

  • username (str) – Username for the MQTT broker on the TV, typically “hisenseservice”.

  • password (str) – Password for the MQTT broker on the TV, typically “multimqttservice”.

  • timeout (Union[int, float]) – Duration to wait for a response from the TV for API calls.

  • enable_client_logger (bool) – Enable MQTT client logging for debug.

  • ssl_context (Optional[SSLContext]) – SSL context to utilize for the connection, None to skip SSL usage (required for some models).

get_sources()

Gets the video sources from the TV.

Return type

List[Dict[str, str]]

Returns

List of source dictionaries.

Example:

[
    {
        "displayname": "TV",
        "hotel_mode": "0",
        "is_lock": "false",
        "is_signal": "1",
        "sourceid": "1",
        "sourcename": "TV",
    },
    {
        "displayname": "HDMI 1",
        "hotel_mode": "0",
        "is_lock": "false",
        "is_signal": "0",
        "sourceid": "2",
        "sourcename": "HDMI 1",
    },
    {
        "displayname": "HDMI 2",
        "hotel_mode": "0",
        "is_lock": "false",
        "is_signal": "0",
        "sourceid": "3",
        "sourcename": "HDMI 2",
    },
    {
        "displayname": "HDMI 3",
        "hotel_mode": "0",
        "is_lock": "false",
        "is_signal": "0",
        "sourceid": "4",
        "sourcename": "HDMI 3",
    },
    {
        "displayname": "PC",
        "hotel_mode": "0",
        "is_lock": "false",
        "is_signal": "1",
        "sourceid": "5",
        "sourcename": "HDMI 4",
    },
    {
        "displayname": "Composite",
        "hotel_mode": "0",
        "is_lock": "false",
        "is_signal": "0",
        "sourceid": "6",
        "sourcename": "Composite",
    },
]

get_volume()

Gets the volume level on the TV.

Return type

dict

Returns

Dictionary with keys for volume_type and volume_value.

Example:

{"volume_type": 0, "volume_value": 0}

send_authorization_code(code)

Sends the authorization code to the TV.

Parameters

code (Union[int, str]) – 4-digit code as displayed on the TV.

Raises

HisenseTvAuthorizationError – Failed to authenticate with the TV.

send_key(keyname)

Sends a keypress to the TV, as if it had been pressed on the IR remote.

Parameters

keyname (str) – Name of the key press to send.

send_key_back()

Sends a keypress of the back key to the TV.

send_key_down()

Sends a keypress of the down key to the TV.

send_key_exit()

Sends a keypress of the exit key to the TV.

send_key_fast_forward()

Sends a keypress of the fast forward key to the TV.

send_key_left()

Sends a keypress of the left key to the TV.

send_key_menu()

Sends a keypress of the menu key to the TV.

send_key_ok()

Sends a keypress of the OK key to the TV.

send_key_pause()

Sends a keypress of the stop key to the TV.

send_key_play()

Sends a keypress of the play key to the TV.

send_key_power()

Sends a keypress of the powerkey to the TV.

send_key_rewind()

Sends a keypress of the rewind key to the TV.

send_key_right()

Sends a keypress of the right key to the TV.

send_key_stop()

Sends a keypress of the stop key to the TV.

send_key_up()

Sends a keypress of the up key to the TV.

send_key_volume_down()

Sends a keypress of the volume down key to the TV.

send_key_volume_up()

Sends a keypress of the volume up key to the TV.

set_source(sourceid, sourcename)

Sets the video source on the TV.

Parameters
  • sourceid (Union[int, str]) – Numeric source identier.

  • sourcename (str) – Human readable source name.

set_volume(volume)

Sets the volume level on the TV.

Parameters

volume (int) – Volume level from 0-100.

Raises

ValueError – Volume level is out of range.

start_authorization()

Starts the authorization flow.

exception hisensetv.HisenseTvAuthorizationError

Raised upon authorization failures.

exception hisensetv.HisenseTvError

Base exception for all exceptions raise by this API.

exception hisensetv.HisenseTvNotConnectedError

Raised when an API function is called without a connection.

exception hisensetv.HisenseTvTimeoutError

Raised upon a failure to receive a response in the timeout period.