-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
56 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,63 @@ | ||
from abc import abstractmethod | ||
from abc import ABC, abstractmethod | ||
from typing import Optional, List, Type | ||
|
||
from typing import List, Optional | ||
from custom_components.sat.helpers import snake_case | ||
|
||
MANUFACTURERS = { | ||
"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", | ||
"Atag": 4, | ||
"Baxi": 4, | ||
"Brotge": 4, | ||
"DeDietrich": 4, | ||
"Ferroli": 9, | ||
"Geminox": 4, | ||
"Ideal": 6, | ||
"Immergas": 27, | ||
"Intergas": 173, | ||
"Itho": 29, | ||
"Nefit": 131, | ||
"Radiant": 41, | ||
"Remeha": 11, | ||
"Sime": 27, | ||
"Vaillant": 24, | ||
"Viessmann": 33, | ||
"Worcester": 95, | ||
"Other": -1, | ||
} | ||
|
||
|
||
class Manufacturer: | ||
class Manufacturer(ABC): | ||
def __init__(self, member_id: int): | ||
self._member_id = member_id | ||
|
||
@property | ||
@abstractmethod | ||
def identifier(self) -> int: | ||
pass | ||
def member_id(self) -> int: | ||
return self._member_id | ||
|
||
@property | ||
@abstractmethod | ||
def name(self) -> str: | ||
def friendly_name(self) -> str: | ||
pass | ||
|
||
|
||
class ManufacturerFactory: | ||
@staticmethod | ||
def all() -> List[Manufacturer]: | ||
"""Resolve a list of all Manufacturer instances.""" | ||
return [ | ||
ManufacturerFactory._import_class(module, name)() | ||
for name, module in MANUFACTURERS.items() | ||
] | ||
|
||
@staticmethod | ||
def resolve_by_name(name: str) -> Optional[Manufacturer]: | ||
"""Resolve a Manufacturer instance by its name.""" | ||
if not (module := MANUFACTURERS.get(name)): | ||
if not (member_id := MANUFACTURERS.get(name)): | ||
return None | ||
|
||
return ManufacturerFactory._import_class(module, name)() | ||
return ManufacturerFactory._import_class(snake_case(name), name)(member_id) | ||
|
||
@staticmethod | ||
def resolve_by_member_id(member_id: int) -> List[Manufacturer]: | ||
"""Resolve a list of Manufacturer instances by member ID.""" | ||
return [ | ||
manufacturer | ||
for manufacturer in ManufacturerFactory.all() | ||
if manufacturer.identifier == member_id | ||
ManufacturerFactory._import_class(snake_case(name), name)(identifier) | ||
for name, identifier in MANUFACTURERS.items() | ||
if member_id == identifier | ||
] | ||
|
||
@staticmethod | ||
def _import_class(module_name: str, class_name: str): | ||
def _import_class(module_name: str, class_name: str) -> Type[Manufacturer]: | ||
"""Dynamically import and return a Manufacturer class.""" | ||
return getattr(__import__(f"custom_components.sat.manufacturers.{module_name}", fromlist=[class_name]), class_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
from ..manufacturer import Manufacturer | ||
|
||
|
||
class ATAG(Manufacturer): | ||
class Atag(Manufacturer): | ||
@property | ||
def identifier(self) -> int: | ||
return 4 | ||
|
||
@property | ||
def name(self) -> str: | ||
def friendly_name(self) -> str: | ||
return 'ATAG' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters