use dhid for get the devicehub_id of the real parth of a device
This commit is contained in:
parent
a222b37ecc
commit
60f7ee8354
|
@ -75,7 +75,7 @@ class InventoryView(LoginMixin, SnapshotMixin):
|
||||||
self.response = jsonify(
|
self.response = jsonify(
|
||||||
{
|
{
|
||||||
'url': snapshot.device.url.to_text(),
|
'url': snapshot.device.url.to_text(),
|
||||||
'dhid': snapshot.device.devicehub_id,
|
'dhid': snapshot.device.dhid,
|
||||||
'sid': snapshot.sid,
|
'sid': snapshot.sid,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -324,16 +324,13 @@ class Device(Thing):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def public_link(self) -> str:
|
def public_link(self) -> str:
|
||||||
if self.binding:
|
|
||||||
return self.binding.device.public_link
|
|
||||||
|
|
||||||
host_url = request.host_url.strip('/')
|
host_url = request.host_url.strip('/')
|
||||||
return "{}{}".format(host_url, self.url.to_text())
|
return "{}{}".format(host_url, self.url.to_text())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self) -> urlutils.URL:
|
def url(self) -> urlutils.URL:
|
||||||
"""The URL where to GET this device."""
|
"""The URL where to GET this device."""
|
||||||
return urlutils.URL(url_for_resource(Device, item_id=self.devicehub_id))
|
return urlutils.URL(url_for_resource(Device, item_id=self.dhid))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rate(self):
|
def rate(self):
|
||||||
|
@ -618,6 +615,14 @@ class Device(Thing):
|
||||||
model = self.model or ''
|
model = self.model or ''
|
||||||
return f'{type} {manufacturer} {model}'
|
return f'{type} {manufacturer} {model}'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dhid(self):
|
||||||
|
if self.placeholder:
|
||||||
|
return self.placeholder.device.devicehub_id
|
||||||
|
if self.binding:
|
||||||
|
return self.binding.device.devicehub_id
|
||||||
|
return self.devicehub_id
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def __mapper_args__(cls):
|
def __mapper_args__(cls):
|
||||||
"""Defines inheritance.
|
"""Defines inheritance.
|
||||||
|
|
|
@ -114,7 +114,7 @@ class Device(Thing):
|
||||||
sku = SanitizedStr(description=m.Device.sku.comment)
|
sku = SanitizedStr(description=m.Device.sku.comment)
|
||||||
image = URL(description=m.Device.image.comment)
|
image = URL(description=m.Device.image.comment)
|
||||||
allocated = Boolean(description=m.Device.allocated.comment)
|
allocated = Boolean(description=m.Device.allocated.comment)
|
||||||
devicehub_id = SanitizedStr(
|
dhid = SanitizedStr(
|
||||||
data_key='devicehubID', description=m.Device.devicehub_id.comment
|
data_key='devicehubID', description=m.Device.devicehub_id.comment
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Reference in New Issue