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

Battery level #83

Merged
merged 10 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions VERSION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
24.3
- Fixed DoorLockInverted
- Security Update. DZGA now reads smart-home-key.json file from config folder. Move .json file or upload a new.
- Added new device, Door Lock Inverted.
- Changed check version, get latest updates.
24.4
- Fixes Lighting 4 devices
- Added battery level on dashboard devices
- Added Enerygystorgae trait uses to check battery level
10 changes: 8 additions & 2 deletions modules/domoticz.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def getAog(device, user_id=None):
'name': device.get('Name'),
'nicknames': []
}
if device.get('Type') in ['Light/Switch', 'Color Switch', 'Lighting 1', 'Lighting 2', 'Lighting 5', 'RFY', 'Value']:
if device.get('Type') in ['Light/Switch', 'Color Switch', 'Lighting 1', 'Lighting 2', 'Lighting 3','Lighting 4', 'Lighting 5', 'RFY', 'Value']:
aog.type = 'action.devices.types.LIGHT'
if device.get('Image') == 'WallSocket':
aog.type = 'action.devices.types.OUTLET'
Expand Down Expand Up @@ -168,7 +168,7 @@ def getAog(device, user_id=None):
aog.customData['idx'] = device.get('idx')
aog.customData['domain'] = domain
aog.customData['protected'] = device.get('Protected')
aog.notificationSupportedByAgent = (True if domain in ['SmokeDetector', 'Doorbell', 'DoorLock', 'DoorLockInverted'] else False)
aog.notificationSupportedByAgent = (True if domain in ['SmokeDetector', 'Doorbell', 'DoorLock', 'DoorLockInverted'] else False)

if domain == 'Scene':
aog.type = 'action.devices.types.SCENE'
Expand Down Expand Up @@ -342,6 +342,12 @@ def getAog(device, user_id=None):
],
'cameraStreamNeedAuthToken': False
}

batteryLevel = device.get('BatteryLevel')
if domain not in ['Group', 'Scene'] and batteryLevel != 255:
aog.traits.append('action.devices.traits.EnergyStorage')
aog.attributes['queryOnlyEnergyStorage'] = True
aog.attributes['isRechargeable'] = False

return aog

Expand Down
28 changes: 27 additions & 1 deletion modules/trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,33 @@ def query(custom_data, device, user_id):
response["isArmed"] = state['Data'] != "Normal"
if response["isArmed"]:
response["currentArmLevel"] = state['Data']

if 'action.devices.traits.EnergyStorage' in device['traits']:
if state['BatteryLevel'] != 255:
battery = state['BatteryLevel']
if battery is not None:
if battery == 100:
descriptive_capacity_remaining = "FULL"
elif 75 <= battery < 100:
descriptive_capacity_remaining = "HIGH"
elif 25 <= battery < 75:
descriptive_capacity_remaining = "MEDIUM"
elif 10 <= battery < 25:
descriptive_capacity_remaining = "LOW"
elif 0 <= battery < 10:
descriptive_capacity_remaining = "CRITICALLY_LOW"

response['descriptiveCapacityRemaining'] = descriptive_capacity_remaining
response['capacityRemaining'] = [{
'unit': 'PERCENTAGE',
'rawValue': battery
}]


response['online'] = True
if domain not in ['Group', 'Scene'] and state['BatteryLevel'] != 255:
if state['BatteryLevel'] <= 10: # Report low battery below 10%
response['exceptionCode'] = 'lowBattery'

return response

Expand Down Expand Up @@ -251,7 +276,8 @@ def execute(device, command, params, user_id, challenge):
response['online'] = True
return response
else:
return {"status": "ERROR", "errorCode": "streamUnavailable"}
raise SmartHomeError('streamUnavailable',
'Unable to execute {} for {}'.format(command, device['id']))

if command == 'action.devices.commands.ArmDisarm':

Expand Down
53 changes: 52 additions & 1 deletion static/js/smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,22 @@ function refreshTemp(updateTemp) {
var temp = jsonData.result[0].Temp;
var setpoint = jsonData.result[0].SetPoint
var lastUpdate = jsonData.result[0].LastUpdate
var batterylevel = jsonData.result[0].BatteryLevel
if (lastUpdate != null){
$('#lastUpdate_' + idx).html(moment(lastUpdate).fromNow())
}
if (batterylevel != 255){
$('#batteryLevel_' + idx).addClass('bi bi-battery-full')
if (batterylevel <= 50){
$('#batteryLevel_' + idx).removeClass('bi bi-battery-full')
$('#batteryLevel_' + idx).addClass('bi bi-battery-half')
}
if (batterylevel <= 15){
$('#batteryLevel_' + idx).removeClass('bi bi-battery-full')
$('#batteryLevel_' + idx).addClass('bi bi-battery').css('color','#ED2939')
}
$('#batteryLevel_' + idx).html(batterylevel + '%&nbsp;')
};
$('button[id="switch_' + idx + '"]').html(data)
$('#data_'+ idx).html(data)
$('#actual_data_'+ idx).html(temp)
Expand All @@ -87,9 +100,22 @@ function refreshSwitches(updateSwitches) {
requestAPI(url).then(jsonData => {
var data = jsonData.result[0].Data;
var lastUpdate = jsonData.result[0].LastUpdate
var batterylevel = jsonData.result[0].BatteryLevel
if (lastUpdate != null){
$('#lastUpdate_' + idx).html(moment(lastUpdate).fromNow())
};
if (batterylevel != 255){
$('#batteryLevel_' + idx).addClass('bi bi-battery-full')
if (batterylevel <= 50){
$('#batteryLevel_' + idx).removeClass('bi bi-battery-full')
$('#batteryLevel_' + idx).addClass('bi bi-battery-half')
}
if (batterylevel <= 15){
$('#batteryLevel_' + idx).removeClass('bi bi-battery-full')
$('#batteryLevel_' + idx).addClass('bi bi-battery').css('color','#ED2939')
}
$('#batteryLevel_' + idx).html(batterylevel + '%&nbsp;')
};
$('button[id="switch_' + idx + '"]').html(data);
$('#data_' + idx).html(data);

Expand Down Expand Up @@ -149,6 +175,19 @@ function refreshSelectors(updateSelector) {
if (lastUpdate != null){
$('#lastUpdate_' + idx).html(moment(lastUpdate).fromNow())
}
var batterylevel = jsonData.result[0].BatteryLevel
if (batterylevel != 255){
$('#batteryLevel_' + idx).addClass('bi bi-battery-full')
if (batterylevel <= 50){
$('#batteryLevel_' + idx).removeClass('bi bi-battery-full')
$('#batteryLevel_' + idx).addClass('bi bi-battery-half')
}
if (batterylevel <= 15){
$('#batteryLevel_' + idx).removeClass('bi bi-battery-full')
$('#batteryLevel_' + idx).addClass('bi bi-battery').css('color','#ED2939')
}
$('#batteryLevel_' + idx).html(batterylevel + '%&nbsp;')
};
btns = decodeBase64(levelnames).split('|');
$.each(btns, function (i, lvlname) {
if (i != '0') {
Expand Down Expand Up @@ -222,7 +261,19 @@ function refreshDimmers(updateDimmers) {
if (lastUpdate != null){
$('#lastUpdate_' + idx).html(moment(lastUpdate).fromNow())
}

var batterylevel = jsonData.result[0].BatteryLevel
if (batterylevel != 255){
$('#batteryLevel_' + idx).addClass('bi bi-battery-full')
if (batterylevel <= 50){
$('#batteryLevel_' + idx).removeClass('bi bi-battery-full')
$('#batteryLevel_' + idx).addClass('bi bi-battery-half')
}
if (batterylevel <= 15){
$('#batteryLevel_' + idx).removeClass('bi bi-battery-full')
$('#batteryLevel_' + idx).addClass('bi bi-battery').css('color','#ED2939')
}
$('#batteryLevel_' + idx).html(batterylevel + '%&nbsp;')
};
if (jsonData.result[0].Type == 'Color Switch'){
var color = JSON.parse(jsonData.result[0].Color)
var color_decimal = color.r * 65536 + color.g * 256 + color.b
Expand Down
Loading
Loading