Skip to content

Commit

Permalink
add a status cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mralext20 committed Jun 8, 2024
1 parent 675c41d commit c3e6a52
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion alexBot/cogs/smartHome.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PhoneMonitor(Cog):
def __init__(self, bot: "Bot"):
super().__init__(bot)
self.notifiable: List[int] = list(USER_TO_HA_DEVICE.keys())
self.status_cache = {}

@discord.app_commands.command(name="ha-vc-notifs", description="Toggle voice channel notifications for your phone")
@discord.app_commands.guilds(GUILD)
Expand Down Expand Up @@ -270,7 +271,9 @@ async def on_presence_update(self, before: discord.Member, after: discord.Member
if before.status != after.status:
mqtt: HomeAssistantIntigreation = self.bot.get_cog("HomeAssistantIntigreation") # type: ignore
blob = {"status": after.status.value, "mobile": after.is_on_mobile()}
await mqtt.mqttPublish(f"discord/{after.id}/status", json.dumps(blob))
self.status_cache[after.id] = blob
if self.status_cache[before.id] != blob:
await mqtt.mqttPublish(f"discord/{after.id}/status", json.dumps(blob))


async def setup(bot: "Bot"):
Expand Down

0 comments on commit c3e6a52

Please sign in to comment.