Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/connectedto #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion pytryfi/fiPet.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,31 @@ def setPetDetailsJSON(self, petJSON):
self._device.setDeviceDetailsJSON(petJSON['device'])
except Exception as e:
capture_exception(e)
self._connectedTo = self.setConnectedTo(petJSON['device']['lastConnectionState'])

def __str__(self):
return f"Last Updated - {self.lastUpdated} - Pet ID: {self.petId} Name: {self.name} Is Lost: {self.isLost} From: {self.homeCityState} ActivityType: {self.activityType} Located: {self.currLatitude},{self.currLongitude} Last Updated: {self.currStartTime}\n \
return f"Last Updated - {self.lastUpdated} - Pet ID: {self.petId} Name: {self.name} Connected To: {self.connectedTo} Is Lost: {self.isLost} From: {self.homeCityState} ActivityType: {self.activityType} Located: {self.currLatitude},{self.currLongitude} Last Updated: {self.currStartTime}\n \
using Device/Collar: {self._device}"

# set the connected to friendly string
def setConnectedTo(self, connectedToJSON):
connectedToString = ""
try:
typename = connectedToJSON['__typename']
if typename == 'ConnectedToUser':
connectedToString = connectedToJSON['user']['firstName'] + " " + connectedToJSON['user']['lastName']
elif typename == 'ConnectedToCellular':
connectedToString = "Cellular! Signal Strength - " + str(connectedToJSON['signalStrengthPercent'])
elif typename == 'ConnectedToBase':
connectedToString = "Base ID - " + connectedToJSON['chargingBase']['id']
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an additional connection state that can be returned

      "lastConnectionState": {
          "__typename": "ConnectedToWifi",
          "date": "2022-06-08T06:10:57.475Z"
      }

connectedToString = "Unknown!"
return connectedToString
except Exception as e:
LOGGER.error(f"Exception setting ConnectTo {e}")
capture_exception(e)
return "Unknown!"

# set the Pet's current location details
def setCurrentLocation(self, activityJSON):
activityType = activityJSON['__typename']
Expand Down Expand Up @@ -294,6 +314,10 @@ def activityType(self):
def areaName(self):
return self._areaName

@property
def connectedTo(self):
return self._connectedTo

def getBirthDate(self):
return datetime.datetime(self.yearOfBirth, self.monthOfBirth, self.dayOfBirth)

Expand Down