1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.AddressTypes import AddressType, AddressTypes
5 from PLC.Addresses import Address, Addresses
6 from PLC.Auth import Auth
8 class DeleteAddressTypeFromAddress(Method):
10 Deletes an address type from the specified address.
12 PIs may only update addresses of their own sites.
14 Returns 1 if successful, faults otherwise.
17 roles = ['admin', 'pi']
21 Mixed(AddressType.fields['address_type_id'],
22 AddressType.fields['name']),
23 Address.fields['address_id']
26 returns = Parameter(int, '1 if successful')
29 def call(self, auth, address_type_id_or_name, address_id):
30 address_types = AddressTypes(self.api, [address_type_id_or_name])
32 raise PLCInvalidArgument, "No such address type"
33 address_type = address_types[0]
35 addresses = Addresses(self.api, [address_id])
37 raise PLCInvalidArgument, "No such address"
38 address = addresses[0]
40 if 'admin' not in self.caller['roles']:
41 if address['site_id'] not in self.caller['site_ids']:
42 raise PLCPermissionDenied, "Address must be associated with one of your sites"
44 address.remove_address_type(address_type)
45 self.object_ids = [address['address_id']]