From 00f4d4fc4c29e09ab93207666ac51c05f49dc1d7 Mon Sep 17 00:00:00 2001 From: Matt Alexander Date: Tue, 1 Aug 2023 03:58:05 -0500 Subject: [PATCH] Fix Issue #1: "Edid objects lack a string representation of PNP ID" (#5) --- pyedid/__init__.py | 1 + pyedid/types/edid.py | 1 + pyedid/types/registry.py | 10 +++++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pyedid/__init__.py b/pyedid/__init__.py index 85b9dea..58458ff 100644 --- a/pyedid/__init__.py +++ b/pyedid/__init__.py @@ -88,6 +88,7 @@ def parse_edid(raw: Union[bytes, str], registry: Registry = DEFAULT_REGISTRY) -> return Edid( manufacturer_id = raw_edid.manu_id, manufacturer = registry.get_company_by_raw(raw_edid.manu_id), + manufacturer_pnp_id = registry.get_company_pnp_id(raw_edid.manu_id), product_id = raw_edid.prod_id, year = raw_edid.manu_year + 1990, week = raw_edid.manu_week, diff --git a/pyedid/types/edid.py b/pyedid/types/edid.py index bd6535f..adb34ae 100644 --- a/pyedid/types/edid.py +++ b/pyedid/types/edid.py @@ -10,6 +10,7 @@ class Edid(NamedTuple): '''Parsed EDID object''' manufacturer_id: int manufacturer: str + manufacturer_pnp_id: str product_id: int year: int week: int diff --git a/pyedid/types/registry.py b/pyedid/types/registry.py index f397fe0..39b544a 100644 --- a/pyedid/types/registry.py +++ b/pyedid/types/registry.py @@ -148,11 +148,15 @@ def get_company_by_pnp(self, pnp_id: str) -> str: '''Convert PNP id to company name or 'Unknown' if not found''' return self.get(pnp_id, self.__DEFAULT_NAME) - def get_company_by_raw(self, raw_id: int) -> str: + def get_company_pnp_id(self, raw_id: int) -> str: '''Convert raw edid value to company name or 'Unknown' if not found''' tmp = [(raw_id >> 10) & 31, (raw_id >> 5) & 31, raw_id & 31] try: - pnp_id = ''.join(string.ascii_uppercase[n-1] for n in tmp) - return self.get_company_by_pnp(pnp_id) + return ''.join(string.ascii_uppercase[n-1] for n in tmp) except IndexError: return self.__DEFAULT_NAME + + def get_company_by_raw(self, raw_id: int) -> str: + '''Convert raw edid value to PNP ID or 'Unknown' if not found''' + pnp_id = self.get_company_pnp_id(raw_id) + return self.get_company_by_pnp(pnp_id)