Skip to content

Commit 5980e12

Browse files
authored
Merge pull request #150 from peternewman/plugfest
Handle loading models with no device_model_description present
2 parents d516137 + 460ea8a commit 5980e12

16 files changed

+104
-48
lines changed

data/model_data.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
8482L: [{'device_model': 38,
2222
'model_description': 'LED BAR',
2323
'product_category': 1289,
24-
'software_versions': {1: {'label': 'V1.02 \x00LED BAR\x00BRITEQ',
24+
'software_versions': {1: {
25+
#'label': 'V1.02 \x00LED BAR\x00BRITEQ',
2526
'languages': [],
2627
'manufacturer_pids': [],
2728
'personalities': [{'description': ' \x00\x08',
@@ -57,5 +58,21 @@
5758
224,
5859
225,
5960
1024]}},
60-
'sub_device_count': 0}]
61+
'sub_device_count': 0}],
62+
25711L: [{'device_model': 30,
63+
# 'model_description': 'LinearDC720W',
64+
'product_category': 1289,
65+
'software_versions': {254: {'label': '254',
66+
'languages': [],
67+
'manufacturer_pids': [],
68+
'personalities': [],
69+
'sensors': [{'description': 'TNTC',
70+
'index': 0,
71+
'supports_recording': 0,
72+
'type': 0}],
73+
'supported_parameters': [128,
74+
129,
75+
512,
76+
513]}},
77+
'sub_device_count': 0}],
6178
}

model.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Manufacturer(db.Model):
3838
"""Represents a Manufacturer."""
3939
esta_id = db.IntegerProperty(required=True)
4040
name = db.StringProperty(required=True)
41-
# link to the product page
41+
# link to the manufacturer website
4242
link = db.LinkProperty();
4343
# url of the source image
4444
image_url = db.LinkProperty();
@@ -58,12 +58,13 @@ class Responder(db.Model):
5858
manufacturer = db.ReferenceProperty(Manufacturer, required=True)
5959
# The Device Model ID field from DEVICE_INFO
6060
device_model_id = db.IntegerProperty()
61-
# The DEVICE_MODEL_DESCRIPTION
62-
model_description = db.StringProperty(required=True)
61+
# Description can't be required, as DEVICE_MODEL_DESCRIPTION is not a
62+
# mandatory PID.
63+
model_description = db.StringProperty(default=None)
6364
# The product category
6465
product_category = db.ReferenceProperty(ProductCategory,
6566
collection_name='responder_set')
66-
# link to the product page
67+
# link to the responder product page
6768
link = db.LinkProperty();
6869
# url of the source image
6970
image_url = db.LinkProperty();
@@ -100,8 +101,11 @@ class SoftwareVersion(db.Model):
100101
"""Represents a particular software version on a responder."""
101102
# Version id
102103
version_id = db.IntegerProperty(required=True)
103-
# Version label
104-
label = db.StringProperty(default='')
104+
# Version label should be required, as SOFTWARE_VERSION_LABEL is a mandatory
105+
# PID but we've had real world devices without it, or there could be issues
106+
# with their implementation such as it being empty (which App Engine treats
107+
# as not present)
108+
label = db.StringProperty(default=None)
105109
# supported params
106110
supported_parameters = db.ListProperty(int)
107111
# reference to the responder this version is associated with
@@ -112,8 +116,9 @@ class SoftwareVersion(db.Model):
112116

113117
class ResponderPersonality(db.Model):
114118
"""Represents a personality of a responder."""
115-
# TODO(simon): make description required some time once we have all the data.
116-
description = db.StringProperty()
119+
# Description can't be required, as DMX_PERSONALITY_DESCRIPTION is not a
120+
# mandatory PID.
121+
description = db.StringProperty(default=None)
117122
index = db.IntegerProperty(required=True)
118123
# Sometimes we know a personality exists, but not the description or the slot
119124
# count.
@@ -126,7 +131,11 @@ class ResponderPersonality(db.Model):
126131

127132
class ResponderSensor(db.Model):
128133
"""Represents a Sensor on a responder."""
129-
description = db.StringProperty(required=True)
134+
# Sensor description should be required, as the description field is part of
135+
# the SENSOR_DEFINITION PID but there may be real world devices with issues
136+
# with their implementation such as it being empty (which App Engine treats
137+
# as not present)
138+
description = db.StringProperty(default=None)
130139
index = db.IntegerProperty(required=True)
131140
type = db.IntegerProperty(required=True)
132141
supports_min_max_recording = db.BooleanProperty()

model_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def GetTemplateData(self):
6565
'rating': model.rdm_responder_rating,
6666
'star_width': rating_scale,
6767
}
68+
if hasattr(model.manufacturer, 'name') and model.manufacturer.name:
69+
output['manufacturer_name'] = model.manufacturer.name
6870
if model.image_data:
6971
serving_url = model.image_serving_url
7072
if not serving_url:

model_loader.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@ def Update(self):
5454
for manufacturer_id, models in self._model_data.iteritems():
5555
manufacturer = self._LookupManufacturer(manufacturer_id)
5656
if not manufacturer:
57-
logging.error('No manufacturer found for %hx' % manufacturer_id)
57+
logging.error('No manufacturer found for 0x%hx' % manufacturer_id)
5858
continue
5959

6060
for model_info in models:
6161
was_added, was_modified = self._updater.UpdateResponder(
6262
manufacturer, model_info)
6363

64+
model_description = model_info.get('model_description')
65+
if model_description is None:
66+
model_description = ('RDM Model 0x%04x' % model_info.get('device_model', 0))
6467
if was_added:
65-
added.append(model_info['model_description'])
68+
added.append(model_description)
6669
elif was_modified:
67-
updated.append(model_info['model_description'])
70+
updated.append(model_description)
6871

6972
return added, updated
7073

@@ -189,7 +192,7 @@ def _AddResponder(self, manufacturer, model_id, model_info):
189192
responder = Responder(
190193
manufacturer = manufacturer,
191194
device_model_id = model_id,
192-
model_description = model_info['model_description'])
195+
model_description = model_info.get('model_description'))
193196

194197
# add product_category if there is one
195198
product_category_id = model_info.get('product_category')
@@ -222,7 +225,7 @@ def _AddSoftwareVersion(self, responder, version_id, version_info):
222225
"""
223226
# create the new version object and store it
224227
version_obj = SoftwareVersion(version_id = version_id,
225-
label = version_info.get('label', ''),
228+
label = version_info.get('label'),
226229
responder = responder)
227230
supported_params = version_info.get('supported_parameters')
228231
if supported_params:
@@ -269,7 +272,7 @@ def _UpdatePersonalities(self, software_version, personalities):
269272
# add any new personalities
270273
for index, personality_info in new_personalities.iteritems():
271274
personality = ResponderPersonality(
272-
description = personality_info.get('description', ''),
275+
description = personality_info.get('description'),
273276
index = index,
274277
sw_version = software_version)
275278
if 'slot_count' in personality_info:

product_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def Update(self):
175175
for manufacturer_id, products in self._product_data.iteritems():
176176
manufacturer = self._LookupManufacturer(manufacturer_id)
177177
if not manufacturer:
178-
logging.error('No manufacturer found for %hx' % manufacturer_id)
178+
logging.error('No manufacturer found for 0x%hx' % manufacturer_id)
179179
continue
180180

181181
for product_info in products:

templates/about.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
about RDM enabled products.
1515
</p>
1616

17-
<h3>Adding & Changing Information</h3>
17+
<h3>Adding &amp; Changing Information</h3>
1818

1919
We're more than happy to list new products. Please see the sections below for
2020
how to add information.

templates/admin.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
<div class="btn-group-vertical" role="group">
4545
<div>/admin?action=clear_p - Clear PIDs</div>
46-
<div>/admin?action=clear_mp&manufacturer=1234 - Clear Manufacturer PIDs</div>
46+
<div>/admin?action=clear_mp&amp;manufacturer=1234 - Clear Manufacturer PIDs</div>
4747
<!-- These deliberately aren't links, so people don't click them accidentally -->
4848
<a class="btn btn-default" href="/admin?action=load_p">Load ESTA PIDs</a>
4949
<a class="btn btn-default" href="/admin?action=load_mp">Load Manufacturer PIDs</a>

templates/base_model_search.tmpl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
<tbody>
2424
{% for model in models %}
2525
<tr class="results_row"
26-
onclick="window.location='/model/display?manufacturer={{ model.manufacturer.esta_id }}&model={{ model.device_model_id }}'">
26+
onclick="window.location='/model/display?manufacturer={{ model.manufacturer.esta_id }}&amp;model={{ model.device_model_id }}'">
2727
<td>{{ model.manufacturer.name }}</td>
28-
<td>{{ model.device_model_id }} ( 0x{{ model.device_model_id|stringformat:"04x" }} )</td>
29-
<td>{{ model.model_description }}</td>
28+
<td>{{ model.device_model_id }} (0x{{ model.device_model_id|stringformat:"04x" }})</td>
29+
<td>
30+
{% if model.model_description %}
31+
{{ model.model_description }}
32+
{% endif %}
33+
</td>
3034
</tr>
3135
{% endfor %}
3236
</tbody>
@@ -38,4 +42,4 @@
3842
<script type="text/javascript">
3943
app.makeModelTable("model_table");
4044
</script>
41-
{% endblock %}
45+
{% endblock %}

templates/base_pid_search.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<tbody>
3333
{% for pid in pids %}
3434
<tr class="results_row"
35-
onclick="window.location='/pid/display?manufacturer={{ pid.manufacturer.esta_id }}&pid={{ pid.pid_id }}'">
35+
onclick="window.location='/pid/display?manufacturer={{ pid.manufacturer.esta_id }}&amp;pid={{ pid.pid_id }}'">
3636
<td>{{ pid.manufacturer.name }}</td>
3737
<td>0x{{ pid.manufacturer.esta_id|stringformat:"04hx"}}</td>
3838
<td>0x{{ pid.pid_id|stringformat:"04hx" }}</td>
@@ -62,4 +62,4 @@
6262
<script type="text/javascript">
6363
app.makePIDTable("pid_table");
6464
</script>
65-
{% endblock %}
65+
{% endblock %}

templates/browse_models.tmpl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,20 @@
3333
{% for row in model_rows %}
3434
{% for model in row %}
3535
<div class="panel panel-default model_panel"
36-
onclick="location.href='/model/display?manufacturer={{ model.manufacturer_id }}&model={{ model.model_id }}'">
37-
<div class="panel-heading" onclick="location.href='/model/display?manufacturer={{ model.manufacturer_id }}&model={{ model.model_id }}'">
38-
{{ model.name }}
36+
onclick="location.href='/model/display?manufacturer={{ model.manufacturer_id }}&amp;model={{ model.model_id }}'">
37+
<div class="panel-heading" onclick="location.href='/model/display?manufacturer={{ model.manufacturer_id }}&amp;model={{ model.model_id }}'">
38+
{% if model.name %}
39+
{{ model.name }}
40+
{% else %}
41+
{% if model.manufacturer_name %}
42+
{{ model.manufacturer_name }}
43+
{% else %}
44+
{{ model.manufacturer_id|stringformat:"04x" }}
45+
{% endif %}
46+
- Model ID {{ model.model_id }}
47+
{% endif %}
3948
</div>
40-
<div class="panel-body" onclick="location.href='/model/display?manufacturer={{ model.manufacturer_id }}&model={{ model.model_id }}'">
49+
<div class="panel-body" onclick="location.href='/model/display?manufacturer={{ model.manufacturer_id }}&amp;model={{ model.model_id }}'">
4150
{% if model.image_key %}
4251
<img src="{{ model.image_key }}=s100">
4352
{% else %}
@@ -104,4 +113,4 @@
104113
{% endfor %}
105114
{% endfor %}
106115
</script>
107-
{% endblock %}
116+
{% endblock %}

0 commit comments

Comments
 (0)