Skip to content

Commit

Permalink
renamed PyDSS to pydss in DEFAULT_REGISTRY
Browse files Browse the repository at this point in the history
  • Loading branch information
KapilDuwadi committed Mar 25, 2024
1 parent 0f0b87b commit f2ec277
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/pydss/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,25 @@
"name": "NO_VRT",
"filename": os.path.join(
os.path.dirname(getattr(pydss, "__path__")[0]),
"PyDSS/pyControllers/Controllers/Settings/PvControllers.toml"
"pydss/pyControllers/Controllers/Settings/PvControllers.toml",
),
},
{
"name": "cpf",
"filename": os.path.join(
os.path.dirname(getattr(pydss, "__path__")[0]),
"PyDSS/pyControllers/Controllers/Settings/PvControllers.toml"
"pydss/pyControllers/Controllers/Settings/PvControllers.toml",
),
},
{
"name": "volt-var",
"filename": os.path.join(
os.path.dirname(getattr(pydss, "__path__")[0]),
"PyDSS/pyControllers/Controllers/Settings/PvControllers.toml"
"pydss/pyControllers/Controllers/Settings/PvControllers.toml",
),
},
],
ControllerType.PV_VOLTAGE_RIDETHROUGH.value: [
],
ControllerType.PV_VOLTAGE_RIDETHROUGH.value: [],
ControllerType.SOCKET_CONTROLLER.value: [],
ControllerType.STORAGE_CONTROLLER.value: [],
ControllerType.XMFR_CONTROLLER.value: [],
Expand All @@ -52,24 +51,26 @@

REQUIRED_CONTROLLER_FIELDS = ("name", "filename")


class Registry:
"""Manages controllers registered with pydss."""

_REGISTRY_FILENAME = ".pydss-registry.json"

def __init__(self, registry_filename=None):
if registry_filename is None:
self._registry_filename = Path.home() / self._REGISTRY_FILENAME
else:
self._registry_filename = Path(registry_filename)

self._controllers = {x: {} for x in CONTROLLER_TYPES}
data = copy.deepcopy(DEFAULT_REGISTRY)
for controller_type, controllers in DEFAULT_REGISTRY["Controllers"].items():
for controller in controllers:
path = Path(controller["filename"])
if not path.exists():
raise InvalidConfiguration(f"Default controller file={path} does not exist")

# This is written to work with legacy versions where default controllers were
# written to the registry.
if self._registry_filename.exists():
Expand All @@ -80,15 +81,20 @@ def __init__(self, registry_filename=None):
path = Path(controller["filename"])
if not path.exists():
name = controller["name"]
msg = f"The registry contains a controller with an invalid file. " \
f"Type={controller_type} name={name} file={path}.\nWould you like to " \
"delete it? (y/n) -> "
msg = (
f"The registry contains a controller with an invalid file. "
f"Type={controller_type} name={name} file={path}.\nWould you like to "
"delete it? (y/n) -> "
)
response = input(msg).lower()
if response == "y":
to_delete.append((controller_type, i))
continue
else:
logger.error("Exiting because the registry %s is invalid", self._registry_filename)
logger.error(
"Exiting because the registry %s is invalid",
self._registry_filename,
)
sys.exit(1)
if not self._is_default_controller(controller_type, controller["name"]):
data["Controllers"][controller_type].append(controller)
Expand Down Expand Up @@ -231,9 +237,7 @@ def unregister_controller(self, controller_type, name):
"""
if not self.is_controller_registered(controller_type, name):
raise InvalidParameter(
f"{controller_type} / {name} isn't registered"
)
raise InvalidParameter(f"{controller_type} / {name} isn't registered")
if self._is_default_controller(controller_type, name):
raise InvalidParameter(f"Cannot unregister a default controller")

Expand Down

0 comments on commit f2ec277

Please sign in to comment.