From 673bb9876c2054cfe64b11f6aa3fc5bd9cfbe2dc Mon Sep 17 00:00:00 2001 From: Boosik Date: Sat, 18 Jan 2020 02:55:19 +0100 Subject: [PATCH] Add support for custom status --- custom_components/discord_game/manifest.json | 2 +- custom_components/discord_game/sensor.py | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/custom_components/discord_game/manifest.json b/custom_components/discord_game/manifest.json index bc80d21..1cf7f78 100644 --- a/custom_components/discord_game/manifest.json +++ b/custom_components/discord_game/manifest.json @@ -4,5 +4,5 @@ "documentation": "", "dependencies": [], "codeowners": [], - "requirements": ["discord.py==1.2.4"] + "requirements": ["git+https://github.com/Rapptz/discord.py@23f16618fdf5fcbeeefed7acb56b579e74bc88d8#egg=discord.py-custom-status"] } \ No newline at end of file diff --git a/custom_components/discord_game/sensor.py b/custom_components/discord_game/sensor.py index 6757b34..2ce3a9e 100644 --- a/custom_components/discord_game/sensor.py +++ b/custom_components/discord_game/sensor.py @@ -4,14 +4,14 @@ import homeassistant.helpers.config_validation as cv import voluptuous as vol -from discord import ActivityType, Spotify, Game, Streaming, Activity, Member, User +from discord import ActivityType, Spotify, Game, Streaming, CustomActivity, Activity, Member, User from homeassistant.components.notify import PLATFORM_SCHEMA from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_START) from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['discord.py==1.2.4'] +REQUIREMENTS = ['discord.py==1.6.0'] CONF_TOKEN = 'token' CONF_MEMBERS = 'members' @@ -69,6 +69,8 @@ def update_discord_entity(watcher: DiscordAsyncMemberState, discord_member: Memb watching = None watching_details = None watching_url = None + custom_status = None + custom_emoji = None for activity in discord_member.activities: if activity.type == ActivityType.playing: @@ -108,6 +110,12 @@ def update_discord_entity(watcher: DiscordAsyncMemberState, discord_member: Memb watching_details = activity.details watching_url = activity.url continue + if activity.type == ActivityType.custom: + activity: CustomActivity + activity_state = activity.state + custom_status = activity.name + custom_emoji = activity.emoji.name + continue watcher._game = game watcher._streaming = streaming @@ -128,6 +136,8 @@ def update_discord_entity(watcher: DiscordAsyncMemberState, discord_member: Memb watcher._watching_url = watching_url watcher._watching_details = watching_details watcher._activity_state = activity_state + watcher._custom_status = custom_status + watcher._custom_emoji = custom_emoji watcher.async_schedule_update_ha_state() def update_discord_entity_user(watcher: DiscordAsyncMemberState, discord_user: User): @@ -195,6 +205,8 @@ def __init__(self, hass, client, member): self._avatar_url = None self._avatar_id = None self._user_id = None + self._custom_status = None + self._custom_emoji = None @property def should_poll(self) -> bool: @@ -238,7 +250,9 @@ def device_state_attributes(self): 'spotify_end': self._spotify_end, 'watching': self._watching, 'watching_url': self._watching_url, - 'watching_details': self._watching_details + 'watching_details': self._watching_details, + 'custom_status': self._custom_status, + 'custom_emoji': self._custom_emoji } def update(self):