Automatically assign a phone number to new devices
This commit is contained in:
parent
027e4b3a7f
commit
2d31abd1c3
@ -13,6 +13,7 @@ class DectConfig:
|
|||||||
def check(self):
|
def check(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self, c):
|
def __init__(self, c):
|
||||||
self._c = c
|
self._c = c
|
||||||
@ -20,3 +21,28 @@ class Config:
|
|||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
return self.dect.check()
|
return self.dect.check()
|
||||||
|
|
||||||
|
|
||||||
|
class ExtensionConfig:
|
||||||
|
def __init__(self, c):
|
||||||
|
self.num = c[0]
|
||||||
|
self._c = c[1]
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
if name in self._c.keys():
|
||||||
|
return self._c.get(name)
|
||||||
|
else:
|
||||||
|
raise AttributeError()
|
||||||
|
|
||||||
|
|
||||||
|
class Extensions:
|
||||||
|
def __init__(self, c):
|
||||||
|
self._c = c
|
||||||
|
self.extensions = []
|
||||||
|
for e in self._c.get("extensions", {}).items():
|
||||||
|
self.extensions.append(ExtensionConfig(e))
|
||||||
|
|
||||||
|
def extensions_by_type(self, t):
|
||||||
|
for e in self.extensions:
|
||||||
|
if e.type == t:
|
||||||
|
yield e
|
||||||
|
@ -15,10 +15,33 @@ class Dect:
|
|||||||
ommsync=True,
|
ommsync=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_temp_number(self):
|
||||||
|
temp_num_prefix = next(self.fp.extensions.extensions_by_type("temp")).num
|
||||||
|
current_temp_extension = 0
|
||||||
|
used_temp_extensions = [u.num[len(temp_num_prefix):] for u in self.c.find_users(lambda u: u.num.startswith(temp_num_prefix))]
|
||||||
|
|
||||||
|
while "{:0>4}".format(current_temp_extension) in used_temp_extensions:
|
||||||
|
current_temp_extension += 1
|
||||||
|
|
||||||
|
return "{}{:0>4}".format(temp_num_prefix, current_temp_extension)
|
||||||
|
|
||||||
|
def get_sip_password_for_number(self, num):
|
||||||
|
return num
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._init_client()
|
self._init_client()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print("meow")
|
unbound_devices = self.c.find_devices(lambda d: d.relType == mitel_ommclient2.types.PPRelTypeType("Unbound"))
|
||||||
print(self.c.ping())
|
|
||||||
|
for d in unbound_devices:
|
||||||
|
print(d)
|
||||||
|
temp_num = self.get_temp_number()
|
||||||
|
u = self.c.create_user(temp_num)
|
||||||
|
print(u)
|
||||||
|
self.c.attach_user_device(u.uid, d.ppn)
|
||||||
|
self.c.set_user_relation_fixed(u.uid)
|
||||||
|
self.c.set_user_sipauth(u.uid, temp_num, self.get_sip_password_for_number(temp_num))
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
@ -27,4 +27,4 @@ class FieldPOC:
|
|||||||
self.config = config.Config(json.loads(self.config_file_path.read_text()))
|
self.config = config.Config(json.loads(self.config_file_path.read_text()))
|
||||||
|
|
||||||
def _load_extensions(self):
|
def _load_extensions(self):
|
||||||
self.extensions = json.loads(self.extensions_file_path.read_text())
|
self.extensions = config.Extensions(json.loads(self.extensions_file_path.read_text()))
|
||||||
|
@ -1 +1,17 @@
|
|||||||
{}
|
{
|
||||||
|
"extensions": {
|
||||||
|
"2574": {
|
||||||
|
"name": "clerie",
|
||||||
|
"type": "dect",
|
||||||
|
"dect_claim_token": "2574"
|
||||||
|
},
|
||||||
|
"9998": {
|
||||||
|
"name": "Temporary Numbers",
|
||||||
|
"type": "temp"
|
||||||
|
},
|
||||||
|
"9999": {
|
||||||
|
"name": "DECT Claim Token Pool",
|
||||||
|
"type": "claim_token"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user