Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions providers/base/units/graphics/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ id: graphics/{index}_auto_glxgears_{product_slug}
flags: also-after-suspend
requires:
executable.name == 'glxgears'
dmi.sane_product == "portable"
dmi.display_type == "integrated"
user: root
command:
# shellcheck disable=SC1091
Expand Down Expand Up @@ -385,7 +385,7 @@ id: graphics/{index}_valid_glxgears_{product_slug}
flags: also-after-suspend
requires:
executable.name == 'glxgears'
dmi.sane_product == "portable"
dmi.display_type == "integrated"
user: root
command:
# shellcheck disable=SC1091
Expand Down Expand Up @@ -414,7 +414,7 @@ id: graphics/{index}_auto_glxgears_fullscreen_{product_slug}
flags: also-after-suspend
requires:
executable.name == 'glxgears'
dmi.sane_product == "portable"
dmi.display_type == "integrated"
user: root
command:
# shellcheck disable=SC1091
Expand All @@ -435,7 +435,7 @@ id: graphics/{index}_valid_glxgears_fullscreen_{product_slug}
flags: also-after-suspend
requires:
executable.name == 'glxgears'
dmi.sane_product == "portable"
dmi.display_type == "integrated"
user: root
command:
# shellcheck disable=SC1091
Expand Down
2 changes: 1 addition & 1 deletion providers/base/units/monitor/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ template-resource: graphics_card
template-filter: graphics_card.prime_gpu_offload == 'Off'
id: monitor/{index}_dim_brightness_{product_slug}
template-id: monitor/index_dim_brightness_product_slug
requires: dmi.sane_product == "portable"
requires: dmi.display_type == "integrated"
plugin: user-interact-verify
category_id: com.canonical.plainbox::monitor
user: root
Expand Down
26 changes: 25 additions & 1 deletion providers/resource/bin/dmi_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def sane_product(og_product: str) -> str:
The product key is basically free-form text. In order to make it more
usable in resource expressions, which usually want to know if a device is
portable (a laptop/tablet) or not, this cleans up the key to a "canonical"
answer, either `non-portable` or `portable`
answer, either `non-portable` or `portable`.
"""
cleaned = og_product.lower().replace(" ", "-")
if cleaned in [
Expand All @@ -44,6 +44,7 @@ def sane_product(og_product: str) -> str:
"space-saving",
"all-in-one",
"aio",
"mini-pc",
"main-server-chassis",
]:
return "non-portable"
Expand All @@ -59,6 +60,28 @@ def sane_product(og_product: str) -> str:
return "unknown"


def display_type(og_product: str) -> str:
"""Return whether this product has an integrated display.

This is orthogonal to portability: both laptops and AIOs have
integrated displays, while desktops typically do not.
Returns either `integrated` or `external`.
"""
cleaned = og_product.lower().replace(" ", "-")
if cleaned in [
"notebook",
"laptop",
"portable",
"convertible",
"tablet",
"detachable",
"all-in-one",
"aio",
]:
return "integrated"
return "external"


class DmiResult:

attributes = (
Expand All @@ -80,6 +103,7 @@ def addDmiDevice(self, device):
print("{}: {}".format(attribute, value))
if attribute == "product" and value:
print("{}: {}".format("sane_product", sane_product(value)))
print("{}: {}".format("display_type", display_type(value)))

print()

Expand Down
35 changes: 33 additions & 2 deletions providers/resource/tests/test_dmi_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def test_sane_product_non_portable(self):
"Tower",
"Mini-Tower",
"Space Saving",
"All-in-One",
"aio",
"Mini PC",
]
category = set(map(dmi_resource.sane_product, products))
self.assertEqual(category, {"non-portable"})
Expand All @@ -54,3 +53,35 @@ def test_sane_product_unknown(self):
products = ["strange-iot-product"]
category = set(map(dmi_resource.sane_product, products))
self.assertEqual(category, {"unknown"})

def test_display_type_integrated(self):
products = [
"Notebook",
"Laptop",
"Portable",
"Convertible",
"Tablet",
"Detachable",
"All-In-One",
"All In One",
"AIO",
]
category = set(map(dmi_resource.display_type, products))
self.assertEqual(category, {"integrated"})

def test_display_type_external(self):
products = [
"Desktop",
"Low Profile Desktop",
"Tower",
"Mini-Tower",
"Space Saving",
"Mini PC",
]
category = set(map(dmi_resource.display_type, products))
self.assertEqual(category, {"external"})

def test_display_type_unknown(self):
products = ["strange-iot-product"]
category = set(map(dmi_resource.display_type, products))
self.assertEqual(category, {"external"})
Loading