Skip to content

Commit

Permalink
Refactor module write_nix method to include priority parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
elikoga committed Jan 17, 2024
1 parent d4ae3e7 commit 3d71ffb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions controller/app/models/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def ser_model(self, nxt: SerializerFunctionWrapHandler):
def write_nix(
self,
path: os.PathLike,
env: Environment,
module_settings: models.ModuleSettings,
priority: int,
):
filename = f"{self.type}.nix"

Expand All @@ -54,6 +54,6 @@ def write_nix(
for attr, value in module_settings.settings.items():
my_attr = getattr(self, attr)
assert isinstance(my_attr, models.Setting)
my_attr.write_nix(f, value, module_settings.priority)
my_attr.write_nix(f, value, i)

f.write("}\n")
1 change: 0 additions & 1 deletion controller/app/models/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ class SettingValue(BaseModel):

class ModuleSettings(BaseModel):
type: str # type of module this settings object is for
priority: int
settings: Dict[str, SettingValue]
6 changes: 4 additions & 2 deletions controller/app/models/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
models.Thymis,
]

HOST_PRIORITY = 100


class State(BaseModel):
version: str
Expand Down Expand Up @@ -48,7 +50,7 @@ def write_nix(self, path: os.PathLike):
for module_settings in device.modules:
# module holds settings right now.
module = next(m for m in self.modules if m.type == module_settings.type)
module.write_nix(device_path, env, module_settings)
module.write_nix(device_path, env, module_settings, HOST_PRIORITY)
# for each tag create its own folder
for tag in self.tags:
tag_path = path / "tags" / tag.name
Expand All @@ -57,7 +59,7 @@ def write_nix(self, path: os.PathLike):
for module_settings in tag.modules:
# module holds settings right now.
module = next(m for m in self.modules if m.type == module_settings.type)
module.write_nix(tag_path, env, module_settings)
module.write_nix(tag_path, env, module_settings, tag.priority)

def available_modules(self):
# return all modules that are not already included in the state
Expand Down

0 comments on commit 3d71ffb

Please sign in to comment.