Skip to content

Application

pyfamilysafety.application.Application

Application(api, user_id)

An application from the member's app activity report.

Attributes:

Name Type Description
app_id

Application identifier (prefix indicates platform).

name

Display name.

icon

Icon URL.

policy

Raw policy object from the API.

blocked bool

Whether the app is currently blocked.

Source code in pyfamilysafety/application.py
26
27
28
29
30
31
32
33
34
def __init__(self, api: FamilySafetyAPI, user_id):
    self.app_id = None
    self.name = None
    self.icon = None
    self._usage = None
    self.policy = None
    self.blocked: bool = None
    self._api: FamilySafetyAPI = api
    self._user_id = user_id

app_id instance-attribute

app_id = None

name instance-attribute

name = None

icon instance-attribute

icon = None

policy instance-attribute

policy = None

blocked instance-attribute

blocked = None

usage property

usage

Screen time used by this app in the current report period.

Returns:

Type Description
float

Usage in minutes (converted from milliseconds in the API).

update

update(app)

Updates the data.

Source code in pyfamilysafety/application.py
36
37
38
39
40
41
42
43
def update(self, app: 'Application'):
    """Updates the data."""
    self.app_id = app.app_id
    self.name = app.name
    self.icon = app.icon
    self._usage = (app.usage*60)*1000
    self.policy = app.policy
    self.blocked = app.blocked

block_app async

block_app()

Block this application from running.

Posts an app policy update with blockState set to BlockedAlways. Updates :attr:blocked to True on success.

Source code in pyfamilysafety/application.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
async def block_app(self):
    """Block this application from running.

    Posts an app policy update with ``blockState`` set to ``BlockedAlways``.
    Updates :attr:`blocked` to ``True`` on success.
    """
    await self._api.send_request(
        endpoint="set_app_policy",
        body={
            "appId": self.app_id,
            "appTimeEnforcementPolicy": "WeekendAndWeekday",
            "blockState": "BlockedAlways",
            "blocked": False,
            "displayName": self.app_id,
            "enabled": True
        },
        USER_ID=self._user_id,
        APP_ID=self.app_id,
        platform=get_platform(self.app_id)
    )
    self.blocked = True

unblock_app async

unblock_app()

Remove the block on this application.

Posts an app policy update with blockState set to NotBlocked. Updates :attr:blocked to False on success.

Source code in pyfamilysafety/application.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
async def unblock_app(self):
    """Remove the block on this application.

    Posts an app policy update with ``blockState`` set to ``NotBlocked``.
    Updates :attr:`blocked` to ``False`` on success.
    """
    await self._api.send_request(
        endpoint="set_app_policy",
        body={
            "appId": self.app_id,
            "appTimeEnforcementPolicy": "WeekendAndWeekday",
            "blockState": "NotBlocked",
            "blocked": False,
            "displayName": self.app_id,
            "enabled": True
        },
        USER_ID=self._user_id,
        APP_ID=self.app_id,
        platform=get_platform(self.app_id)
    )
    self.blocked = False

from_app_activity_report classmethod

from_app_activity_report(raw_response, api, user_id)

Converts the activity report into a list of applications.

Source code in pyfamilysafety/application.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
@classmethod
def from_app_activity_report(cls, raw_response: dict, api, user_id) -> list['Application']:
    """Converts the activity report into a list of applications."""
    parsed_apps = []
    if "appActivity" in raw_response.keys():
        apps = raw_response.get("appActivity")
        for app in apps:
            parsed = cls(api, user_id)
            parsed.app_id = app["appId"]
            parsed.name = app["displayName"]
            parsed.icon = app["iconUrl"]
            parsed._usage = app["usage"]
            parsed.policy = app["policy"]
            parsed.blocked = (app["blockState"] == "Blocked") or (
                app["isLegacyBlocked"]) or (
                    app["blockState"] == "BlockedAlways"
                )
            parsed_apps.append(parsed)
    else:
        raise ValueError("Missing appActivity in JSON response.")
    return parsed_apps