diff --git a/function/ground_floor_west.py b/function/ground_floor_west.py index 4e26106..8ecadd7 100644 --- a/function/ground_floor_west.py +++ b/function/ground_floor_west.py @@ -7,7 +7,7 @@ import devices from function.modules import brightness_choose_n_action, heating_function import logging from function.rooms import room -from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate +from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate, videv_audio_player import task try: @@ -152,6 +152,8 @@ class ground_floor_west_dirk(room): self.desk_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE) self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE) self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE) + self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY) + self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD) self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE) super().__init__(mqtt_client) # @@ -178,9 +180,6 @@ class ground_floor_west_dirk(room): self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT, self.powerplug_common.toggle_output_3_mcb) - # Mediaplayer - Spotify / MPD state - self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY) - self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD) # Mediaplayer - Amplifier auto on self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.powerplug_common.set_output_0_mcb, True) self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True) @@ -295,6 +294,10 @@ class ground_floor_west_dirk(room): mqtt_client, config.TOPIC_GFW_DIRK_ACTIVE_BRIGHTNESS_DEVICE_VIDEV, brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 3 ) + self.audio_player_videv = videv_audio_player( + mqtt_client, config.TOPIC_GFW_DIRK_AUDIO_PLAYER_VIDEV, + self.spotify_state, self.mpd_state + ) # # Other stuff # diff --git a/function/videv.py b/function/videv.py index 702e2f3..16d6222 100644 --- a/function/videv.py +++ b/function/videv.py @@ -16,9 +16,7 @@ Targets: from base import mqtt_base import devices -import inspect import json -import logging BASETOPIC = "videv" @@ -99,10 +97,10 @@ class base_routing(base): l1 = [] for k, v in self.__device_list__.items(): if v.__class__.__name__ == "group": - if device in v: + if id(device) in [id(d) for d in v]: l1.append(k) else: - if v == device: + if id(v) == id(device): l1.append(k) l2 = [k for k, v in self.__device_key__.items() if v == key] try: @@ -234,15 +232,38 @@ class videv_heating(base_routing): class videv_multistate(base): - def __init__(self, mqtt_client, topic, key_for_topic, device, num_states, default_values=None): + def __init__(self, mqtt_client, topic, key_for_device, device, num_states, default_values=None): dv = dict.fromkeys(["state_%d" % i for i in range(0, num_states)]) for key in dv: dv[key] = False - super().__init__(mqtt_client, topic, (key_for_topic, device), default_values=dv) + super().__init__(mqtt_client, topic, (key_for_device, device), default_values=dv) # - device.add_callback(key_for_topic, None, self.__index_rx__, True) + device.add_callback(key_for_device, None, self.__index_rx__, True) def __index_rx__(self, device, key, data): for index, key in enumerate(self): self.set(key, index == data) self.__tx__(key, self[key]) + + +class videv_audio_player(base_routing): + KEY_ACTIVE_PLAYER = 'player_%d' + KEY_TITLE = 'title' + NO_TITLE = '---' + + def __init__(self, mqtt_client, topic, *args): + dv = dict.fromkeys([self.KEY_ACTIVE_PLAYER % i for i in range(0, len(args))]) + for key in dv: + dv[key] = False + dv[self.KEY_TITLE] = self.NO_TITLE + super().__init__( + mqtt_client, topic, + *[[self.KEY_ACTIVE_PLAYER % i, device, devices.audio_status.KEY_STATE] for i, device in enumerate(args)], + default_values=dv + ) + for audio_device in args: + audio_device.add_callback(audio_device.KEY_TITLE, None, self.__title_rx__, True) + + def __title_rx__(self, device, key, data): + self.set(self.KEY_TITLE, data or self.NO_TITLE) + self.__tx__(self.KEY_TITLE, self[self.KEY_TITLE])