|
@@ -1,10 +1,17 @@
|
|
import sys
|
|
import sys
|
|
from lib.mqtt import create_client, update_disc, control_player, create_config, check_current_disc
|
|
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()
|
|
client = create_client()
|
|
|
|
|
|
create_config(client)
|
|
create_config(client)
|
|
|
|
|
|
|
|
+use_mqtt = os.environ['use_mqtt'].lower() == 'true'
|
|
|
|
+
|
|
# Check if any arguments are passed
|
|
# Check if any arguments are passed
|
|
if len(sys.argv) > 1:
|
|
if len(sys.argv) > 1:
|
|
# Get the JSON argument from the command line
|
|
# Get the JSON argument from the command line
|
|
@@ -24,17 +31,29 @@ if len(sys.argv) > 1:
|
|
control_player(client, "PLAY")
|
|
control_player(client, "PLAY")
|
|
else:
|
|
else:
|
|
# Pass the parsed data to the update_disc function
|
|
# 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:
|
|
else:
|
|
if input_str == "EJECT":
|
|
if input_str == "EJECT":
|
|
# PAUSE the current playing item
|
|
# PAUSE the current playing item
|
|
- control_player(client, "PAUSE")
|
|
|
|
|
|
+ if use_mqtt:
|
|
|
|
+ control_player(client, "PAUSE")
|
|
|
|
+ else:
|
|
|
|
+ pause_media()
|
|
elif input_str == "PLAY":
|
|
elif input_str == "PLAY":
|
|
# PLAY the current playing item
|
|
# PLAY the current playing item
|
|
- control_player(client, "PLAY")
|
|
|
|
|
|
+ if use_mqtt:
|
|
|
|
+ control_player(client, "PLAY")
|
|
|
|
+ else:
|
|
|
|
+ play_media_again()
|
|
elif input_str == "PAUSE":
|
|
elif input_str == "PAUSE":
|
|
# PAUSE the current playing item
|
|
# PAUSE the current playing item
|
|
- control_player(client, "PAUSE")
|
|
|
|
|
|
+ if use_mqtt:
|
|
|
|
+ control_player(client, "PAUSE")
|
|
|
|
+ else:
|
|
|
|
+ pause_media()
|
|
else:
|
|
else:
|
|
print(f"Can't process {input_str}")
|
|
print(f"Can't process {input_str}")
|