diff --git a/main.py b/main.py index f7156af..ff18048 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,17 @@ import sys from lib.mqtt import create_client, update_disc, control_player, create_config, check_current_disc +from lib.home_assistant import load_disc, pause_media,play_media_again,play_radio,stop_media +from dotenv import load_dotenv +import os + +load_dotenv() client = create_client() create_config(client) +use_mqtt = os.environ['use_mqtt'].lower() == 'true' + # Check if any arguments are passed if len(sys.argv) > 1: # Get the JSON argument from the command line @@ -24,17 +31,29 @@ if len(sys.argv) > 1: control_player(client, "PLAY") else: # Pass the parsed data to the update_disc function - control_player(client, "PLAY") - update_disc(client, disc_data) + if use_mqtt: + control_player(client, "PLAY") + update_disc(client, disc_data) + else: + load_disc(disc_object) else: if input_str == "EJECT": # PAUSE the current playing item - control_player(client, "PAUSE") + if use_mqtt: + control_player(client, "PAUSE") + else: + pause_media() elif input_str == "PLAY": # PLAY the current playing item - control_player(client, "PLAY") + if use_mqtt: + control_player(client, "PLAY") + else: + play_media_again() elif input_str == "PAUSE": # PAUSE the current playing item - control_player(client, "PAUSE") + if use_mqtt: + control_player(client, "PAUSE") + else: + pause_media() else: print(f"Can't process {input_str}") \ No newline at end of file