Skip to content

Commit 68e62f9

Browse files
committed
Use tuple to map category ids to names.
1 parent 44639a0 commit 68e62f9

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

adafruit_ble/services/apple.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ def __get__(self, notification, cls):
7171
notification._attribute_cache[self._id] = value
7272
return value
7373

74+
NOTIFICATION_CATEGORIES = (
75+
"Other",
76+
"IncomingCall",
77+
"MissedCall",
78+
"Voicemail",
79+
"Social",
80+
"Schedule",
81+
"Email",
82+
"News",
83+
"HealthAndFitness",
84+
"BusinessAndFinance",
85+
"Location",
86+
"Entertainment"
87+
)
88+
7489
class Notification:
7590
"""One notification that appears in the iOS notification center."""
7691
# pylint: disable=too-many-instance-attributes
@@ -147,31 +162,7 @@ def update(self, event_flags, category_id, category_count):
147162
def __str__(self):
148163
# pylint: disable=too-many-branches
149164
flags = []
150-
category = None
151-
if self.category_id == 0:
152-
category = "Other"
153-
elif self.category_id == 1:
154-
category = "IncomingCall"
155-
elif self.category_id == 2:
156-
category = "MissedCall"
157-
elif self.category_id == 3:
158-
category = "Voicemail"
159-
elif self.category_id == 4:
160-
category = "Social"
161-
elif self.category_id == 5:
162-
category = "Schedule"
163-
elif self.category_id == 6:
164-
category = "Email"
165-
elif self.category_id == 7:
166-
category = "News"
167-
elif self.category_id == 8:
168-
category = "HealthAndFitness"
169-
elif self.category_id == 9:
170-
category = "BusinessAndFinance"
171-
elif self.category_id == 10:
172-
category = "Location"
173-
elif self.category_id == 11:
174-
category = "Entertainment"
165+
category = NOTIFICATION_CATEGORIES[self.category_id]
175166

176167
if self.silent:
177168
flags.append("silent")

0 commit comments

Comments
 (0)