Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Candle - the privacy friendly smart home authored Feb 16, 2022
1 parent 4e3be91 commit 77ef383
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 46 deletions.
19 changes: 16 additions & 3 deletions js/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,13 @@
}

).then((body) => {
console.log("quick delete ajax API was called succcesfully");
console.log("quick delete ajax API was called succcesfully: ", body);
//thing_list.innerText = body['data'];
//this.show_internal_logs(body['data']);

}).catch((e) => {
//pre.innerText = e.toString();
console.log("Privacy manager: error in quick delete response");
console.log("Privacy manager: error in quick delete response: ", e);
console.log(e.toString());
});

Expand Down Expand Up @@ -681,6 +681,9 @@
//thing_list.innerText = body['data'];
//this.create_thing_list(body['logs']);




if(typeof body.debug != 'undefined'){
if(body.debug){
if(document.getElementById('extension-privacy-manager-debug-warning') != null){
Expand All @@ -689,6 +692,16 @@
}
}

if(typeof body.persistent != 'undefined'){
this.persistent = body['persistent'];

if(typeof body['persistent']['duration'] != 'undefined'){
console.log("setting dropdown to duration: ", body['persistent']['duration']);
document.getElementById('extension-privacy-manager-quick-delete-time-dropdown').value = body['persistent']['duration'];
}

}

if(typeof body.internal_logs_auto_delete != 'undefined'){
//console.log("setting auto-delete internal logs preference to: " + body.internal_logs_auto_delete);
//console.log(internal_logs_auto_delete_checkbox.checked);
Expand All @@ -703,7 +716,7 @@

}).catch((e) => {
//pre.innerText = e.toString();
console.log("Privacy manager: error in show function: ", e);
console.log("Privacy manager: error in show call to api/init: ", e);
});


Expand Down
85 changes: 65 additions & 20 deletions pkg/privacy_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ def __init__(self, verbose=False):
self.should_print_log_name = False



self.duration_lookup_table = {'1':'1 minute',
'10':'10 minutes',
'20':'20 minutes',
'60':'1 hour',
'120':'2 hours',
'240':'4 hours',
'480':'8 hours',
}


#print(str( time(11, 59, 59) ))

try:
Expand Down Expand Up @@ -152,16 +163,17 @@ def __init__(self, verbose=False):

self.get_logs_list()

self.connect_to_printer()

try:
self.adapter = PrivacyManagerAdapter(self,verbose=False)
#self.manager_proxy.add_api_handler(self.extension)
print("ADAPTER created")
if self.DEBUG:
print("ADAPTER created")
pass
except Exception as ex:
print("Failed to start ADAPTER. Error: " + str(ex))

self.connect_to_printer()

self.running = True

try:
Expand All @@ -174,7 +186,8 @@ def __init__(self, verbose=False):
print("Error starting the clock thread: " + str(ex))


print("Privacy manager init complete")
if self.DEBUG:
print("Privacy manager init complete")


#while(self.running):
Expand Down Expand Up @@ -342,8 +355,10 @@ def handle_request(self, request):


if action == 'quick_delete':
#print("in quick delete")
self.persistent_data['duration'] = int(request.body['duration'])
if self.DEBUG:
print("in quick delete")
self.persistent_data['duration'] = int(request.body['duration'])
self.save_persistent_data()
self.quick_delete_filter(self.persistent_data['duration'])

return APIResponse(
Expand Down Expand Up @@ -1861,6 +1876,14 @@ def save_persistent_data(self):





#
# Quick delete thing + filter
#



# Deletes data from ALL logs for the last few minutes/hours
def quick_delete_filter(self,duration):
if self.DEBUG:
Expand All @@ -1882,13 +1905,48 @@ def quick_delete_filter(self,duration):
print("quick deleting. Log_id: " + str(log_id) + ", data_type: " + str(log_data_type) + ", early_time: " + str(early_time) + ", current_time: " + str(current_time))
self.point_delete(log_id,log_data_type, early_time, current_time * 1000)

self.send_pairing_prompt("Deleted the last " + str(duration * 60) + " minutes of log data")
self.adapter.send_pairing_prompt("Deleted the last " + str(duration) + " minutes of log data")

except Exception as ex:
if self.DEBUG:
print("error in quick_delete_filter: " + str(ex))



def duration_name_to_int_lookup(self,duration_string):
if self.DEBUG:
print("in duration_name_to_int_lookup. String: " + str(duration_string))
for key, value in self.duration_lookup_table.items():
if value == duration_string:
if self.DEBUG:
print("Duration reverse lookup success. Returning: " + str(key))
return int(key)
return None


def get_duration_names_list(self):
duration_names = []
for key, value in self.duration_lookup_table.items():
duration_names.append(value)
return duration_names


def thing_delete_button_pushed(self):
if self.DEBUG:
print("(())")
print("in thing_delete_button_pushed")
print("(())")
#self.adapter.send_pairing_prompt("Deleted the last " + "xx" + " minutes of log data")
self.quick_delete_filter(self.persistent_data['duration'])









def run_command_with_lines(self,command):
try:
p = subprocess.Popen(command,
Expand Down Expand Up @@ -1930,19 +1988,6 @@ def run_command_with_lines(self,command):



#
# Handling the thing
#


def thing_delete_button_pushed(self):
if self.DEBUG:
print("(())")
print("in thing_delete_button_pushed")
print("(())")
#self.adapter.send_pairing_prompt("Deleted the last " + "xx" + " minutes of log data")
self.quick_delete_filter(self.persistent_data['duration'])




Expand Down
67 changes: 44 additions & 23 deletions pkg/privacy_manager_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, adapter, api_handler, device_name, device_title, device_type)
self._id = device_name
self.id = device_name
self.adapter = adapter
self.api_handler = api_handler
self.api_handler = self.adapter.api_handler
self._type.append(device_type)
#self._type = ['OnOffSwitch']

Expand All @@ -93,9 +93,9 @@ def __init__(self, adapter, api_handler, device_name, device_title, device_type)

#print("self.api_handler.persistent_data['enabled'] = " + str(self.api_handler.persistent_data['enabled']))

self.properties["data-deletion"] = PrivacyManagerProperty(
self.properties["data_deletion"] = PrivacyManagerProperty(
self,
"data-deletion",
"data_deletion",
{
'@type': 'OnOffProperty',
'title': "Data deletion",
Expand All @@ -104,22 +104,32 @@ def __init__(self, adapter, api_handler, device_name, device_title, device_type)
},
False)

"""
self.properties["anonymous-id"] = PrivacyManagerProperty(
self,
"anonymous-id",
{
'title': "Annymous ID",
'type': 'string',
'readOnly': True
},
self.api_handler.persistent_data['uuid'])


duration_strings_list = self.adapter.api_handler.get_duration_names_list()
if self.adapter.DEBUG:
print("Creating property. Duration_strings_list: " + str(duration_strings_list))

duration_string = duration_strings_list[0]
try:
duration_string = self.adapter.api_handler.duration_lookup_table[ str(self.adapter.api_handler.persistent_data['duration']) ]
print("duration string lookup succeeded? Duration string is now: " + str(duration_string))
except Exception as ex:
print("Error looking up duration in table: " + str(ex))

"""
#targetProperty = self.find_property('outside-access')
#targetProperty.update(self.api_handler.persistent_data['enabled'])
if self.adapter.DEBUG:
print("initial duration string for thing property: " + str(duration_string))

self.properties["data_deletion_duration"] = PrivacyManagerProperty(
self,
"data_deletion_duration",
{
'title': "Time span",
'type': 'string',
'enum': duration_strings_list #["1 minute","10 minutes","30 minutes","1 hour","2 hours","4 hours","8 hours"]
},
duration_string)

#print(str(self.properties["outside-access"]))


#
Expand All @@ -138,22 +148,24 @@ def __init__(self, device, name, description, value):
self.name = name
self.title = name
self.description = description # dictionary
self.value = False
self.set_cached_value(False)
self.value = value
self.set_cached_value(value)
self.device.notify_property_changed(self)
print("privacy manager property initiated")
if self.device.adapter.DEBUG:
print("privacy manager property initiated: " + str(self.name) + ", with value: " + str(self.value))
#self.update(value)
#self.set_cached_value(value)
#self.device.notify_property_changed(self)
#print("property initialized")


def set_value(self, value):
print("set_value is called on a PrivacyManager property: " + str(self.name) + " With new value: " + str(value))
if self.device.adapter.DEBUG:
print("set_value is called on a PrivacyManager property: " + str(self.name) + ", with new value: " + str(value))

try:

if self.name == 'data-deletion':
if self.name == 'data_deletion':
self.value = True
self.set_cached_value(value)
self.device.notify_property_changed(self)
Expand All @@ -168,6 +180,14 @@ def set_value(self, value):
self.set_cached_value(False)
self.device.notify_property_changed(self)

elif self.name == 'data_deletion_duration':
if self.device.adapter.DEBUG:
print("incoming data_deletion_duration enum string: " + str(value))
self.device.adapter.api_handler.persistent_data['duration'] = self.device.adapter.api_handler.duration_name_to_int_lookup(str(value))
if self.device.adapter.DEBUG:
print("self.device.adapter.api_handler.persistent_data['duration'] is now: " + str(self.device.adapter.api_handler.persistent_data['duration']))
self.update(value)

else:
self.update(value)

Expand All @@ -181,7 +201,8 @@ def set_value(self, value):


def update(self, value):
print("privacy_manager property -> update to: " + str(value))
if self.device.adapter.DEBUG:
print("privacy_manager property -> update to: " + str(value))
#print("--prop details: " + str(self.title) + " - " + str(self.original_property_id))
#print("--pro device: " + str(self.device))
if value != self.value:
Expand Down

0 comments on commit 77ef383

Please sign in to comment.