Skip to content

Commit

Permalink
Fix for online status
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeath authored Feb 15, 2023
1 parent dc5945d commit cc1ed37
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions custom_components/roblox_online/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)


BASE_INTERVAL = timedelta(minutes=5)
BASE_INTERVAL = timedelta(minutes=1)


def setup_platform(hass, config, add_entities, discovery_info=None):
Expand Down Expand Up @@ -108,10 +108,8 @@ def update(self):
try:
r = requests.get("https://www.roblox.com/profile?userId=" + self._account)
data = r.json()

self._name = data["Username"]
self._avatar = data["AvatarUri"]

cookies_dict = {".ROBLOSECURITY": self._robloxod}

headers = {
Expand All @@ -124,7 +122,6 @@ def update(self):
self._account,
],
}

response = requests.post(
"https://presence.roblox.com/v1/presence/users",
headers=headers,
Expand All @@ -134,22 +131,22 @@ def update(self):
data = response.json()
userPresence = data.get("userPresences")[0]
self._game_id = userPresence.get("gameId")

self._last_online = userPresence.get("lastOnline")
self._placeId = userPresence.get("placeId")

isOnline = userPresence.get("userPresenceType") > 0

self._game = userPresence.get("lastLocation")

isOnline = int(userPresence.get("userPresenceType")) > 0
if isOnline:
self._state = "online"
self._game = userPresence.get("lastLocation")
self._state = "online"
else:
self._state = "offline"
self._game = "offline"

if self._placeId is not None:
r = requests.get(
"https://thumbnails.roblox.com/v1/assets?assetIds="
+ str(placeId)
+ str(self._placeId)
+ "&size=396x216&format=Png&isCircular=false"
)
data = r.json()
Expand Down

0 comments on commit cc1ed37

Please sign in to comment.