Skip to content

Commit

Permalink
Fix Issue #1: "Edid objects lack a string representation of PNP ID" (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattalxndr committed Aug 1, 2023
1 parent 3ba4a12 commit 00f4d4f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyedid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pyedid/types/edid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions pyedid/types/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 00f4d4f

Please sign in to comment.