1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.PCUs import PCU, PCUs
5 from PLC.Auth import Auth
7 can_update = lambda field_value: field_value[0] not in \
10 class UpdatePCU(Method):
12 Updates the parameters of an existing PCU with the values in
15 Non-admins may only update PCUs at their sites.
17 Returns 1 if successful, faults otherwise.
20 roles = ['admin', 'pi', 'tech']
22 update_fields = dict(list(filter(can_update, list(PCU.fields.items()))))
30 returns = Parameter(int, '1 if successful')
32 def call(self, auth, pcu_id, pcu_fields):
33 pcu_fields = dict(list(filter(can_update, list(pcu_fields.items()))))
35 # Get associated PCU details
36 pcus = PCUs(self.api, [pcu_id])
38 raise PLCInvalidArgument("No such PCU")
41 if 'admin' not in self.caller['roles']:
42 if pcu['site_id'] not in self.caller['site_ids']:
43 raise PLCPermissionDenied("Not allowed to update that PCU")
45 pcu.update(pcu_fields)
46 pcu.update_last_updated(commit=False)
50 self.event_objects = {'PCU': [pcu['pcu_id']]}
51 self.message = 'PCU %d updated: %s' % \
52 (pcu['pcu_id'], ", ".join(list(pcu_fields.keys())))