Skip to content

Commit

Permalink
Merge pull request #45 from bdraco/gen2_battery
Browse files Browse the repository at this point in the history
Additional battery percentage estimations
  • Loading branch information
snjoetw authored Feb 29, 2020
2 parents 9adeef6 + e6eaa3e commit 87dd062
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 6 deletions.
17 changes: 16 additions & 1 deletion august/doorbell.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,21 @@ def __init__(self, data):

self._battery_level = None
if "telemetry" in data:
self._battery_level = data["telemetry"].get("battery_soc", None)
telemetry = data["telemetry"]
if "battery_soc" in telemetry:
self._battery_level = telemetry.get("battery_soc", None)
elif telemetry.get("doorbell_low_battery"):
self._battery_level = 10
elif "battery" in telemetry:
battery = telemetry["battery"]
if battery >= 4:
self._battery_level = 100
elif battery >= 3.75:
self._battery_level = 75
elif battery >= 3.50:
self._battery_level = 50
else:
self._battery_level = 25

@property
def status(self):
Expand Down Expand Up @@ -112,6 +126,7 @@ def image_url(self, var):

@property
def battery_level(self):
"""Return an approximation of the battery percentage."""
return self._battery_level

@property
Expand Down
21 changes: 20 additions & 1 deletion august/keypad.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from august.device import DeviceDetail

BATTERY_LEVEL_FULL = "Full"
BATTERY_LEVEL_MEDIUM = "Medium"
BATTERY_LEVEL_LOW = "Low"


class KeypadDetail(DeviceDetail):
def __init__(self, house_id, keypad_name, data):
Expand All @@ -8,7 +12,7 @@ def __init__(self, house_id, keypad_name, data):
keypad_name,
house_id,
data["serialNumber"],
data["currentFirmwareVersion"]
data["currentFirmwareVersion"],
)

self._battery_level = data["batteryLevel"]
Expand All @@ -20,3 +24,18 @@ def model(self):
@property
def battery_level(self):
return self._battery_level

@property
def battery_percentage(self):
"""Return an approximation of the battery percentage."""
if not self._battery_level:
return None

if self._battery_level == BATTERY_LEVEL_FULL:
return 100
if self._battery_level == BATTERY_LEVEL_MEDIUM:
return 60
if self._battery_level == BATTERY_LEVEL_LOW:
return 10

return 0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='py-august',
version='0.21.0',
version='0.22.0',
packages=['august'],
url='https://github.com/snjoetw/py-august',
license='MIT',
Expand Down
105 changes: 105 additions & 0 deletions tests/fixtures/get_doorbell.battery_full.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"doorbellID": "did",
"serialNumber": "sr",
"appID": "august-iphone-v5",
"installUserID": "iid",
"name": "Front Door",
"installDate": "2019-02-25T05:32:11.263Z",
"pubsubChannel": "pubsub",
"settings": {
"ABREnabled": true,
"auto_contrast_mode": 0,
"backlight_comp": false,
"batteryChargeCurrent": 60,
"batteryLowThreshold": 3.1,
"batteryUseThreshold": 3.4,
"batteryRun": false,
"bellTimerConfig": 50,
"bitrateCeiling": 512000,
"brightness": 50,
"contrast": 50,
"directLink": true,
"debug": false,
"flashBrightness": 40,
"flashDuringCall": true,
"flashOnPIR": true,
"haloBrightnessX": 25,
"hue": 50,
"initialBitrate": 384000,
"IREnabled": true,
"irConfiguration": 16836880,
"irSensitivity": 70,
"IVAEnabled": false,
"JPGQuality": 70,
"keepEncoderRunning": true,
"maintainIVConnection": true,
"micVolume": 100,
"minACNoScaling": 40,
"minimumSnapshotInterval": 30,
"overlayEnabled": true,
"ringSoundEnabled": true,
"saturation": 50,
"sharpness": 50,
"speakerVolume": 92,
"turnOffCamera": false,
"buttonpush_notifications": true,
"motion_notifications": true,
"notify_when_offline": false,
"buttonpush_notifications_partners": false
},
"type": "mars2",
"dvrSubscriptionSetupDone": true,
"secChipCertSerial": null,
"createdAt": "2019-02-25T05:32:11.263Z",
"updatedAt": "2019-02-25T05:50:03.087Z",
"status": "doorbell_call_status_online",
"statusUpdatedAtMs": 1582608961596,
"telemetry": {
"date": "2019-02-25 08:19:56",
"BSSID": "a:b:c",
"SSID": "none",
"wifi_freq": 2437,
"ip_addr": "4.3.3.2",
"link_quality": 70,
"signal_level": -35,
"uptime": "9499.66 7505.92",
"load_average": "0.42 0.39 0.45 2/180 5959",
"temperature": 49.25,
"steady_ac_in": 0,
"battery": 4.147,
"ac_in": 0,
"doorbell_low_battery": false,
"mcu_version": "900aecaf",
"mcu_temp": 61.470001,
"mcu_bat_cur": 63.779999,
"mcu_dc_in": 4.925,
"chg_state": "CHARGING",
"updated_at": "2019-02-25T08:19:58.678Z"
},
"caps": ["reconnect", "webrtc", "no_iv"],
"doorbellServerURL": "https://doorbells.august.com",
"recentImage": {
"public_id": "pubid",
"version": 123,
"signature": "sig",
"width": 480,
"height": 640,
"format": "jpg",
"resource_type": "image",
"created_at": "2020-02-25T05:50:02Z",
"tags": [],
"bytes": 25330,
"type": "upload",
"etag": "etag",
"placeholder": false,
"url": "http://of.jpg",
"secure_url": "https://of.jpg",
"original_filename": "file"
},
"messagingProtocol": "pubnub",
"chimes": [],
"firmwareVersion": "2.3.0-VULRC18+201812100947",
"invitations": [],
"HouseID": "houseid",
"HouseName": "housename"
}
105 changes: 105 additions & 0 deletions tests/fixtures/get_doorbell.battery_low.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"doorbellID": "did",
"serialNumber": "sr",
"appID": "august-iphone-v5",
"installUserID": "iid",
"name": "Front Door",
"installDate": "2019-02-25T05:32:11.263Z",
"pubsubChannel": "pubsub",
"settings": {
"ABREnabled": true,
"auto_contrast_mode": 0,
"backlight_comp": false,
"batteryChargeCurrent": 60,
"batteryLowThreshold": 3.1,
"batteryUseThreshold": 3.4,
"batteryRun": false,
"bellTimerConfig": 50,
"bitrateCeiling": 512000,
"brightness": 50,
"contrast": 50,
"directLink": true,
"debug": false,
"flashBrightness": 40,
"flashDuringCall": true,
"flashOnPIR": true,
"haloBrightnessX": 25,
"hue": 50,
"initialBitrate": 384000,
"IREnabled": true,
"irConfiguration": 16836880,
"irSensitivity": 70,
"IVAEnabled": false,
"JPGQuality": 70,
"keepEncoderRunning": true,
"maintainIVConnection": true,
"micVolume": 100,
"minACNoScaling": 40,
"minimumSnapshotInterval": 30,
"overlayEnabled": true,
"ringSoundEnabled": true,
"saturation": 50,
"sharpness": 50,
"speakerVolume": 92,
"turnOffCamera": false,
"buttonpush_notifications": true,
"motion_notifications": true,
"notify_when_offline": false,
"buttonpush_notifications_partners": false
},
"type": "mars2",
"dvrSubscriptionSetupDone": true,
"secChipCertSerial": null,
"createdAt": "2019-02-25T05:32:11.263Z",
"updatedAt": "2019-02-25T05:50:03.087Z",
"status": "doorbell_call_status_online",
"statusUpdatedAtMs": 1582608961596,
"telemetry": {
"date": "2019-02-25 05:50:01",
"BSSID": "4:d:d",
"SSID": "zip",
"wifi_freq": 2437,
"ip_addr": "1.2.2.4",
"link_quality": 70,
"signal_level": -38,
"uptime": "504.12 380.94",
"load_average": "0.57 0.41 0.22 1/180 1149",
"temperature": 45.625,
"steady_ac_in": 0,
"battery": 3.023,
"ac_in": 0,
"doorbell_low_battery": true,
"mcu_version": "900aecaf",
"mcu_temp": 59.009998,
"mcu_bat_cur": 65,
"mcu_dc_in": 4.978,
"chg_state": "CHARGING",
"updated_at": "2020-02-25T05:50:03.087Z"
},
"caps": ["reconnect", "webrtc", "no_iv"],
"doorbellServerURL": "https://doorbells.august.com",
"recentImage": {
"public_id": "pubid",
"version": 123,
"signature": "sig",
"width": 480,
"height": 640,
"format": "jpg",
"resource_type": "image",
"created_at": "2020-02-25T05:50:02Z",
"tags": [],
"bytes": 25330,
"type": "upload",
"etag": "etag",
"placeholder": false,
"url": "http://of.jpg",
"secure_url": "https://of.jpg",
"original_filename": "file"
},
"messagingProtocol": "pubnub",
"chimes": [],
"firmwareVersion": "2.3.0-VULRC18+201812100947",
"invitations": [],
"HouseID": "houseid",
"HouseName": "housename"
}
105 changes: 105 additions & 0 deletions tests/fixtures/get_doorbell.battery_medium.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"doorbellID": "did",
"serialNumber": "sr",
"appID": "august-iphone-v5",
"installUserID": "iid",
"name": "Front Door",
"installDate": "2019-02-25T05:32:11.263Z",
"pubsubChannel": "pubsub",
"settings": {
"ABREnabled": true,
"auto_contrast_mode": 0,
"backlight_comp": false,
"batteryChargeCurrent": 60,
"batteryLowThreshold": 3.1,
"batteryUseThreshold": 3.4,
"batteryRun": false,
"bellTimerConfig": 50,
"bitrateCeiling": 512000,
"brightness": 50,
"contrast": 50,
"directLink": true,
"debug": false,
"flashBrightness": 40,
"flashDuringCall": true,
"flashOnPIR": true,
"haloBrightnessX": 25,
"hue": 50,
"initialBitrate": 384000,
"IREnabled": true,
"irConfiguration": 16836880,
"irSensitivity": 70,
"IVAEnabled": false,
"JPGQuality": 70,
"keepEncoderRunning": true,
"maintainIVConnection": true,
"micVolume": 100,
"minACNoScaling": 40,
"minimumSnapshotInterval": 30,
"overlayEnabled": true,
"ringSoundEnabled": true,
"saturation": 50,
"sharpness": 50,
"speakerVolume": 92,
"turnOffCamera": false,
"buttonpush_notifications": true,
"motion_notifications": true,
"notify_when_offline": false,
"buttonpush_notifications_partners": false
},
"type": "mars2",
"dvrSubscriptionSetupDone": true,
"secChipCertSerial": null,
"createdAt": "2019-02-25T05:32:11.263Z",
"updatedAt": "2019-02-25T05:50:03.087Z",
"status": "doorbell_call_status_online",
"statusUpdatedAtMs": 1582608961596,
"telemetry": {
"date": "2019-02-25 08:19:56",
"BSSID": "a:b:c",
"SSID": "none",
"wifi_freq": 2437,
"ip_addr": "4.3.3.2",
"link_quality": 70,
"signal_level": -35,
"uptime": "9499.66 7505.92",
"load_average": "0.42 0.39 0.45 2/180 5959",
"temperature": 49.25,
"steady_ac_in": 0,
"battery": 3.82,
"ac_in": 0,
"doorbell_low_battery": false,
"mcu_version": "900aecaf",
"mcu_temp": 61.470001,
"mcu_bat_cur": 63.779999,
"mcu_dc_in": 4.925,
"chg_state": "CHARGING",
"updated_at": "2019-02-25T08:19:58.678Z"
},
"caps": ["reconnect", "webrtc", "no_iv"],
"doorbellServerURL": "https://doorbells.august.com",
"recentImage": {
"public_id": "pubid",
"version": 123,
"signature": "sig",
"width": 480,
"height": 640,
"format": "jpg",
"resource_type": "image",
"created_at": "2020-02-25T05:50:02Z",
"tags": [],
"bytes": 25330,
"type": "upload",
"etag": "etag",
"placeholder": false,
"url": "http://of.jpg",
"secure_url": "https://of.jpg",
"original_filename": "file"
},
"messagingProtocol": "pubnub",
"chimes": [],
"firmwareVersion": "2.3.0-VULRC18+201812100947",
"invitations": [],
"HouseID": "houseid",
"HouseName": "housename"
}
Loading

0 comments on commit 87dd062

Please sign in to comment.