2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.AddressTypes import AddressType, AddressTypes
6 from PLC.Addresses import Address, Addresses
7 from PLC.Auth import Auth
9 class AddAddressTypeToAddress(Method):
11 Adds an address type to the specified address.
13 PIs may only update addresses of their own sites.
15 Returns 1 if successful, faults otherwise.
18 roles = ['admin', 'pi']
22 Mixed(AddressType.fields['address_type_id'],
23 AddressType.fields['name']),
24 Address.fields['address_id']
27 returns = Parameter(int, '1 if successful')
30 def call(self, auth, address_type_id_or_name, address_id):
31 address_types = AddressTypes(self.api, [address_type_id_or_name])
33 raise PLCInvalidArgument, "No such address type"
34 address_type = address_types[0]
36 addresses = Addresses(self.api, [address_id])
38 raise PLCInvalidArgument, "No such address"
39 address = addresses[0]
41 if 'admin' not in self.caller['roles']:
42 if address['site_id'] not in self.caller['site_ids']:
43 raise PLCPermissionDenied, "Address must be associated with one of your sites"
45 address.add_address_type(address_type)
46 self.event_objects = {'Address': [address['address_id']]}