Skip to content

Commit

Permalink
Merge pull request #68 from fan9704/fix_dependencies
Browse files Browse the repository at this point in the history
feature: MQTTListener Exception FCM Notification
  • Loading branch information
fan9704 authored Oct 28, 2023
2 parents f1ffe56 + 576e8ea commit cec7534
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions api/management/commands/callback/recordCallBack.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def temperature_humidity_callback(topic: str, body: str, ch=None, method=None, p
[寵物環境濕度] {humidity}
'''
notify("溫度異常", notify_content, 1)
# Todo: 溫度異常
machine, created = models.Machine.objects.get_or_create(name=topic.split("/")[1])
machine, _ = models.Machine.objects.get_or_create(name=topic.split("/")[1])

temperature_record_type = models.RecordType.objects.get(type="temperature")
humidity_record_type = models.RecordType.objects.get(type="humidity")
Expand All @@ -50,6 +49,8 @@ def weight_callback(topic: str, body: str, ch=None, method=None, properties=None
data = json.loads(body)
logger.info("[Weight] Received " + str(data["Weight"]))
logger.debug(f'Topic:{topic} ch:{ch} properties:{properties} method:{method}')
machine, _ = models.Machine.objects.get_or_create(name=topic.split("/")[1])
weight_record_type = models.RecordType.objects.get(type="weight")

weight = float(data["Weight"])
if weight < 0:
Expand All @@ -58,15 +59,31 @@ def weight_callback(topic: str, body: str, ch=None, method=None, properties=None
'''
notify("進食過少", notify_content, 1)

weight = models.Record.objects.create(
pet=machine.pet,
type=weight_record_type,
data=data["Weight"],
)
weight.save()


def water_callback(topic: str, body: str, ch=None, method=None, properties=None):
data = json.loads(body)
logger.info("[Water] Received " + str(data["Water"]))
logger.debug(f'Topic:{topic} ch:{ch} properties:{properties} method:{method}')
machine, _ = models.Machine.objects.get_or_create(name=topic.split("/")[1])
water_record_type = models.RecordType.objects.get(type="water")

water = float(data["Water"])
if water < 0:
notify_content = f'''
[寵物喝水量] {water}
'''
notify("喝水過少", notify_content, 1)

water = models.Record.objects.create(
pet=machine.pet,
type=water_record_type,
data=data["Water"],
)
water.save()
Binary file modified requirements.txt
Binary file not shown.

0 comments on commit cec7534

Please sign in to comment.