Skip to content

Commit

Permalink
Merge pull request #54 from sbabcock23/issue35
Browse files Browse the repository at this point in the history
Issue35
  • Loading branch information
sbabcock23 authored Aug 25, 2022
2 parents f986067 + 3de8cb7 commit c6efe75
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ Turns on the collar light after dark if the pet is not home.
* Enable possibility of if pet not home and not with owner then trigger lost dog mode

# Version History
## 0.0.16
* Enhancement - requested to add the attributes Activity Type, Current Place Name and Current Place Address.
## 0.0.15
* Version bump to support latest pytryfi version 0.0.16 that includes multiple households
## 0.0.14
Expand Down
4 changes: 2 additions & 2 deletions custom_components/tryfi/manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"domain": "tryfi",
"name": "TryFi",
"version": "0.0.15",
"version": "0.0.16",
"config_flow": true,
"documentation": "https://github.com/sbabcock23/hass-tryfi",
"issue_tracker": "https://github.com/sbabcock23/hass-tryfi/issues",
"requirements": [
"pytryfi>=0.0.16"
"pytryfi>=0.0.17"
],
"dependencies": [],
"iot_class": "cloud_polling",
Expand Down
84 changes: 84 additions & 0 deletions custom_components/tryfi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ async def async_setup_entry(hass, config_entry, async_add_devices):
new_devices.append(
PetStatsSensor(hass, pet, coordinator, statType, statTime)
)
LOGGER.debug(f"Adding Pet Generic Sensor: {pet}")
new_devices.append(PetGenericSensor(hass, pet, coordinator, "Activity Type"))
new_devices.append(PetGenericSensor(hass, pet, coordinator, "Current Place Name"))
new_devices.append(PetGenericSensor(hass, pet, coordinator, "Current Place Address"))

for base in tryfi.bases:
LOGGER.debug(f"Adding Base: {base}")
new_devices.append(TryFiBaseSensor(hass, base, coordinator))
Expand Down Expand Up @@ -105,6 +110,85 @@ def device_info(self):
# "sw_version": self.pet.device.buildId,
}

class PetGenericSensor(CoordinatorEntity, Entity):
"""Representation of a Sensor."""

def __init__(self, hass, pet, coordinator, statType):
self._hass = hass
self._petId = pet.petId
self._statType = statType
super().__init__(coordinator)

@property
def statType(self):
return self._statType

@property
def statTime(self):
return self._statTime

@property
def name(self):
"""Return the name of the sensor."""
return f"{self.pet.name} {self.statType.title()}"

@property
def unique_id(self):
"""Return the ID of this sensor."""
formattedType = self.statType.lower().replace(" ", "-")
return f"{self.pet.petId}-{formattedType}"

@property
def petId(self):
return self._petId

@property
def pet(self):
return self.coordinator.data.getPet(self.petId)

@property
def device(self):
return self.pet.device

@property
def device_id(self):
return self.unique_id

@property
def device_class(self):
"""Return the device class of the sensor."""
return None

@property
def icon(self):
if self.statType == "Activity Type":
return "mdi:run"
elif self.statType == "Current Place Name":
return "mdi:earth"
elif self.statType == "Current Place Address":
return "mdi:map-marker"

@property
def state(self):
if self.statType == "Activity Type":
return self.pet.getActivityType()
elif self.statType == "Current Place Name":
return self.pet.getCurrPlaceName()
elif self.statType == "Current Place Address":
return self.pet.getCurrPlaceAddress()
@property
def unit_of_measurement(self):
return None

@property
def device_info(self):
return {
"identifiers": {(DOMAIN, self.pet.petId)},
"name": self.pet.name,
"manufacturer": "TryFi",
"model": self.pet.breed,
"sw_version": self.pet.device.buildId,
}

class PetStatsSensor(CoordinatorEntity, Entity):
"""Representation of a Sensor."""
Expand Down

0 comments on commit c6efe75

Please sign in to comment.