Skip to content

Commit 5265747

Browse files
Guillaume De Saint MartinGuillaumeDSM
authored andcommitted
[CommunityFeed] add logs
1 parent 2202d85 commit 5265747

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

octobot/community/authentication.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ async def select_bot(self, bot_id):
272272
if fetched_bot is None:
273273
raise errors.BotNotFoundError(f"Can't find bot with id: {bot_id}")
274274
self.user_account.set_selected_bot_raw_data(fetched_bot)
275+
bot_name = self.user_account.get_bot_name_or_id(self.user_account.get_selected_bot_raw_data())
276+
self.logger.debug(f"Selected bot '{bot_name}'")
275277
self.user_account.gql_bot_id = bot_id
276278
self._save_gql_bot_id(self.user_account.gql_bot_id)
277279
await self.on_new_bot_select()

octobot/community/community_user_account.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class CommunityUserAccount:
2222
BOT_DEVICE = "device"
2323
NO_SELECTED_BOT_DESC = "No selected bot. Please select a bot to enable your community features."
2424

25-
2625
def __init__(self):
2726
self.gql_user_id = None
2827
self.gql_bot_id = None
@@ -62,6 +61,12 @@ def get_selected_bot_device_uuid(self):
6261
except AttributeError:
6362
raise errors.NoBotDeviceError("No device associated to the select bot")
6463

64+
def get_selected_bot_device_name(self):
65+
try:
66+
return self.get_selected_bot_raw_data(raise_on_missing=True).get(self.BOT_DEVICE, {}).get("name", None)
67+
except AttributeError:
68+
raise errors.NoBotDeviceError("No device associated to the select bot")
69+
6570
@staticmethod
6671
def get_bot_id(bot):
6772
return bot["_id"]

octobot/community/feeds/community_mqtt_feed.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ async def _connect(self):
267267
self._update_client_config(self._mqtt_client)
268268
self._register_callbacks(self._mqtt_client)
269269
self._mqtt_client.set_auth_credentials(self._device_uuid, None)
270-
self.logger.debug(f"Connecting client")
270+
self.logger.debug(f"Connecting client using device "
271+
f"'{self.authenticator.user_account.get_selected_bot_device_name()}'")
271272
self._connect_task = asyncio.create_task(
272273
self._mqtt_client.connect(self.feed_url, self.mqtt_broker_port, version=self.MQTT_VERSION)
273274
)

tests/unit_tests/community/test_community_mqtt_feed.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
FEED_URL = "x.y.z"
3232
TOKEN = "acb1"
33+
NAME = "name_a"
3334

3435

3536
def _build_message(value, identifier):
@@ -65,6 +66,8 @@ async def connected_community_feed(authenticator):
6566
feed.INIT_TIMEOUT = 1
6667
with mock.patch.object(authenticator.user_account, "get_selected_bot_device_uuid", mock.Mock(return_value=TOKEN)) \
6768
as get_selected_bot_device_uuid_mock, \
69+
mock.patch.object(authenticator.user_account, "get_selected_bot_device_name", mock.Mock(return_value=NAME)
70+
) as _get_selected_bot_device_uuid_mock, \
6871
mock.patch.object(feed, "_subscribe", mock.AsyncMock()) as _subscribe_mock, \
6972
mock.patch.object(gmqtt.Client, "connect", mock.AsyncMock()) as _connect_mock:
7073
await feed.register_feed_callback(commons_enums.CommunityChannelTypes.SIGNAL, mock.AsyncMock())

0 commit comments

Comments
 (0)