Skip to content

Commit

Permalink
Add support for custom status
Browse files Browse the repository at this point in the history
  • Loading branch information
LordBoos committed Jan 18, 2020
1 parent c8add7f commit 673bb98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/discord_game/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
20 changes: 17 additions & 3 deletions custom_components/discord_game/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 673bb98

Please sign in to comment.