Skip to content

Commit

Permalink
Add some more manufacturers and clean some code
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexwijn committed Jan 25, 2025
1 parent 71e9963 commit 571e110
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 23 deletions.
52 changes: 29 additions & 23 deletions custom_components/sat/manufacturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@
from typing import List, Optional

MANUFACTURERS = {
"ATAG": {"module": "atag", "class": "ATAG", "id": 4},
"Baxi": {"module": "baxi", "class": "Baxi", "id": 4},
"Brotge": {"module": "brotge", "class": "Brotge", "id": 4},
"Geminox": {"module": "geminox", "class": "Geminox", "id": 4},
"Ideal": {"module": "ideal", "class": "Ideal", "id": 6},
"Ferroli": {"module": "ferroli", "class": "Ferroli", "id": 9},
"DeDietrich": {"module": "dedietrich", "class": "DeDietrich", "id": 11},
"Vaillant": {"module": "vaillant", "class": "Vaillant", "id": 24},
"Immergas": {"module": "immergas", "class": "Immergas", "id": 27},
"Sime": {"module": "sime", "class": "Sime", "id": 27},
"Viessmann": {"module": "viessmann", "class": "Viessmann", "id": 33},
"Radiant": {"module": "radiant", "class": "Radiant", "id": 41},
"Nefit": {"module": "nefit", "class": "Nefit", "id": 131},
"Intergas": {"module": "intergas", "class": "Intergas", "id": 173},
"Other": {"module": "other", "class": "Other", "id": -1},
"ATAG": "atag",
"Baxi": "baxi",
"Brotge": "brotge",
"DeDietrich": "dedietrich",
"Ferroli": "ferroli",
"Geminox": "geminox",
"Ideal": "ideal",
"Immergas": "immergas",
"Intergas": "intergas",
"Itho": "itho",
"Nefit": "nefit",
"Radiant": "radiant",
"Remeha": "remeha",
"Sime": "sime",
"Vaillant": "vaillant",
"Viessmann": "viessmann",
"Worcester": "worcester",
"Other": "other",
}


class Manufacturer:
@property
@abstractmethod
def identifier(self) -> int:
pass

@property
@abstractmethod
def name(self) -> str:
Expand All @@ -32,23 +40,21 @@ class ManufacturerFactory:
@staticmethod
def resolve_by_name(name: str) -> Optional[Manufacturer]:
"""Resolve a Manufacturer instance by its name."""
manufacturer = MANUFACTURERS.get(name)
if not manufacturer:
if not (module := MANUFACTURERS.get(name)):
return None

return ManufacturerFactory._import_class(manufacturer["module"], manufacturer["class"])()
return ManufacturerFactory._import_class(module, name)()

@staticmethod
def resolve_by_member_id(member_id: int) -> List[Manufacturer]:
"""Resolve a list of Manufacturer instances by member ID."""
return [
ManufacturerFactory._import_class(info["module"], info["class"])()
for name, info in MANUFACTURERS.items()
if info["id"] == member_id
manufacturer
for name, module in MANUFACTURERS.items()
if (manufacturer := ManufacturerFactory._import_class(module, name)()).identifier == member_id
]

@staticmethod
def _import_class(module_name: str, class_name: str):
"""Dynamically import and return a Manufacturer class."""
module = __import__(f"custom_components.sat.manufacturers.{module_name}", fromlist=[class_name])
return getattr(module, class_name)
return getattr(__import__(f"custom_components.sat.manufacturers.{module_name}", fromlist=[class_name]), class_name)
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/atag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class ATAG(Manufacturer):
@property
def identifier(self) -> int:
return 4

@property
def name(self) -> str:
return 'ATAG'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/baxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Baxi(Manufacturer):
@property
def identifier(self) -> int:
return 4

@property
def name(self) -> str:
return 'Baxi'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/brotge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Brotge(Manufacturer):
@property
def identifier(self) -> int:
return 4

@property
def name(self) -> str:
return 'BRÖTGE'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/dedietrich.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class DeDietrich(Manufacturer):
@property
def identifier(self) -> int:
return 4

@property
def name(self) -> str:
return 'De Dietrich'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/ferroli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Ferroli(Manufacturer):
@property
def identifier(self) -> int:
return 9

@property
def name(self) -> str:
return 'Ferroli'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/geminox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Geminox(Manufacturer):
@property
def identifier(self) -> int:
return 4

@property
def name(self) -> str:
return 'Geminox'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Ideal(Manufacturer):
@property
def identifier(self) -> int:
return 6

@property
def name(self) -> str:
return 'Ideal'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/immergas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Immergas(Manufacturer):
@property
def identifier(self) -> int:
return 27

@property
def name(self) -> str:
return 'Immergas'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/intergas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Intergas(Manufacturer):
@property
def identifier(self) -> int:
return 173

@property
def name(self) -> str:
return 'Intergas'
11 changes: 11 additions & 0 deletions custom_components/sat/manufacturers/itho.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ..manufacturer import Manufacturer


class Itho(Manufacturer):
@property
def identifier(self) -> int:
return 29

@property
def name(self) -> str:
return 'Itho'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/nefit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Nefit(Manufacturer):
@property
def identifier(self) -> int:
return 131

@property
def name(self) -> str:
return 'Nefit'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Other(Manufacturer):
@property
def identifier(self) -> int:
return -1

@property
def name(self) -> str:
return 'Other'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/radiant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Radiant(Manufacturer):
@property
def identifier(self) -> int:
return 41

@property
def name(self) -> str:
return 'Radiant'
11 changes: 11 additions & 0 deletions custom_components/sat/manufacturers/remeha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ..manufacturer import Manufacturer


class Remeha(Manufacturer):
@property
def identifier(self) -> int:
return 11

@property
def name(self) -> str:
return 'Remeha'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/sime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Sime(Manufacturer):
@property
def identifier(self) -> int:
return 27

@property
def name(self) -> str:
return 'Sime'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/vaillant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Vaillant(Manufacturer):
@property
def identifier(self) -> int:
return 24

@property
def name(self) -> str:
return 'Vaillant'
4 changes: 4 additions & 0 deletions custom_components/sat/manufacturers/viessmann.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class Viessmann(Manufacturer):
@property
def identifier(self) -> int:
return 33

@property
def name(self) -> str:
return 'Viessmann'
11 changes: 11 additions & 0 deletions custom_components/sat/manufacturers/worcester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ..manufacturer import Manufacturer


class Worcester(Manufacturer):
@property
def identifier(self) -> int:
return 4

@property
def name(self) -> str:
return 'Worcester Bosch'

0 comments on commit 571e110

Please sign in to comment.