Skip to content

Commit

Permalink
Update to support fsa for ders.
Browse files Browse the repository at this point in the history
  • Loading branch information
craig8 committed Sep 13, 2024
1 parent ab26cb4 commit 4522445
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 14 deletions.
7 changes: 7 additions & 0 deletions ieee_2030_5/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ def show_single_dict(self):
_log.debug(pformat(self._singleton_dict, indent=2))

def filter_single_dict(self, fn: Callable) -> Iterator:
"""
Filters the single objects using the specified callable.
The return value will either be None or an Iterator. The None value
will be when no elements match in the given callable.
"""
return filter(fn, self._singleton_dict.keys())

def get(self, list_uri: str, key: int) -> D:
Expand Down
10 changes: 9 additions & 1 deletion ieee_2030_5/adapters/gridappsd_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def _build_device_configurations(self):
pin=int(self._default_pin),
lfdi=self.tls.lfdi(inv.mRID))
dev.ders = [dict(description=inv.name)]
dev.fsas = ["fsa0"]
self._devices.append(dev)
else:
for inv in self.get_power_electronic_connections():
Expand All @@ -276,6 +277,7 @@ def _build_device_configurations(self):
lfdi=self.tls.lfdi(inv.mRID)
)
dev.ders = [dict(description=inv.mRID)]
dev.fsas = ["fsa0"]
self._devices.append(dev)

def get_device_configurations(self) -> list[DeviceConfiguration]:
Expand All @@ -295,7 +297,13 @@ def get_message_for_bus(self) -> dict:
# for dev in self._devices:
# if inverter := next(filter(lambda x: x.lfdi == dev.lfdi, self._inverters):

der_status_uris = adpt.ListAdapter.filter_single_dict(lambda k: k.endswith('ders'))

def detect(v):
if v:
return v.endswith("ders")

der_status_uris = adpt.ListAdapter.filter_single_dict(lambda k: detect(k))


for uri in der_status_uris:
_log.debug(f"Testing uri: {uri}")
Expand Down
3 changes: 3 additions & 0 deletions ieee_2030_5/server/derfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def get(self) -> Response:
# The index that we want to get the control from.
retval = dercl.DERControl[parsed.at(3)]
elif parsed.at(2) == hrefs.DERC:
#retval = adpt.ListAdapter.get_single(request.path)
retval = adpt.ListAdapter.get_resource_list(request.path, start, after, limit)
elif parsed.at(2) == hrefs.DDERC:
retval = adpt.ListAdapter.get_single(request.path)
# elif parsed.at(2) == hrefs.DDERC:
# retval = adpt.DERControlAdapter.fetch_at(parsed.at(3))
else:
Expand Down
10 changes: 8 additions & 2 deletions ieee_2030_5/server/enddevicesfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,17 @@ def get(self) -> Response:
elif request.path == ed.FunctionSetAssignmentsListLink.href:
retval = adpt.ListAdapter.get_resource_list(request.path, start, after, limit)
elif edev_href.count() > 2:
retval = get_href(request.path)
if retval := get_href(request.path):
pass
else:
retval = adpt.ListAdapter.get_resource_list(request.path, start, after, limit)
elif not edev_href.has_index():
retval = m.EndDeviceList(href=request.path, all=1, results=1, EndDevice=[ed])
else:
retval = get_href(request.path)
if retval := get_href(request.path):
pass
else:
retval = adpt.ListAdapter.get_resource_list(request.path, start, after, limit)

# if adpt.ListAdapter.has_list(request.path):
# retval = adpt.ListAdapter.get_resource_list(request.path)
Expand Down
60 changes: 49 additions & 11 deletions ieee_2030_5/server/server_constructs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import annotations

import logging
from venv import create

from blinker import Signal

# from ieee_2030_5.adapters import BaseAdapter
Expand Down Expand Up @@ -168,7 +166,7 @@ def update_active_der_event_ended(event: m.Event):

def create_der_program_and_control(default_der_program: m.DERProgram,
default_der_control: m.DefaultDERControl,
name: str) -> m.DERProgram:
name: str) -> [m.DERProgram, m.DefaultDERControl]:
"""
Create a new DERProgram based upon the default derp control
"""
Expand All @@ -184,13 +182,13 @@ def create_der_program_and_control(default_der_program: m.DERProgram,
derp.ActiveDERControlListLink = m.ActiveDERControlListLink(program_hrefs.active_control_href)
derp.DefaultDERControlLink = m.DefaultDERControlLink(program_hrefs.default_control_href)
derp.DERControlListLink = m.DERControlListLink(program_hrefs.der_control_list_href)
derp.DERCurveListLink = m.DERCurveListLink(program_hrefs.der_curve_list_href)
# derp.DERCurveListLink = m.DERCurveListLink(program_hrefs.der_curve_list_href)

dderc.href = derp.DefaultDERControlLink.href

adpt.ListAdapter.append(hrefs.DEFAULT_DDERC_ROOT, dderc)
adpt.ListAdapter.append(hrefs.DEFAULT_DERP_ROOT, derp)
return derp
return derp, dderc


def initialize_2030_5(config: ServerConfiguration, tlsrepo: TLSRepository):
Expand Down Expand Up @@ -246,7 +244,7 @@ def initialize_2030_5(config: ServerConfiguration, tlsrepo: TLSRepository):
derp.ActiveDERControlListLink = m.ActiveDERControlListLink(program_hrefs.active_control_href)
derp.DefaultDERControlLink = m.DefaultDERControlLink(program_hrefs.default_control_href)
derp.DERControlListLink = m.DERControlListLink(program_hrefs.der_control_list_href)
derp.DERCurveListLink = m.DERCurveListLink(program_hrefs.der_curve_list_href)
#derp.DERCurveListLink = m.DERCurveListLink(program_hrefs.der_curve_list_href)

if config.default_der_control:
# Default DER Control
Expand Down Expand Up @@ -321,9 +319,10 @@ def initialize_2030_5(config: ServerConfiguration, tlsrepo: TLSRepository):
adpt.ListAdapter.append(hrefs.DEFAULT_CURVE_ROOT, curve)

der_global_count = 0

for index, cfg_device in enumerate(config.devices):

create_device_capability(index, cfg_device)
device_capability: m.DeviceCapability = create_device_capability(index, cfg_device)
ed_href = hrefs.EndDeviceHref(index)
end_device = adpt.EndDeviceAdapter.fetch_by_href(str(ed_href))
if end_device is not None:
Expand Down Expand Up @@ -359,9 +358,23 @@ def initialize_2030_5(config: ServerConfiguration, tlsrepo: TLSRepository):
adpt.ListAdapter.initialize_uri(ed_href.der_list, m.DER)
adpt.ListAdapter.initialize_uri(ed_href.function_set_assignments, m.FunctionSetAssignments)

if cfg_device.fsas:
for fsa_name in cfg_device.fsas:
fsa_index = adpt.ListAdapter.list_size(ed_href.function_set_assignments)
fsa = m.FunctionSetAssignments(href=hrefs.SEP.join((ed_href.function_set_assignments,
str(fsa_index))),
description=fsa_name)
adpt.ListAdapter.append(ed_href.function_set_assignments, fsa)

end_device.FunctionSetAssignmentsListLink = m.FunctionSetAssignmentsListLink(
href=ed_href.function_set_assignments,
all=adpt.ListAdapter.list_size(ed_href.function_set_assignments),
)

# If we have ders specified in the configuration file then set those up, otherwise
# if we need to create a default der then set that up.
if cfg_device.ders:

# Create references from the main der list to the ed specific list.
for der in cfg_device.ders:
der_href = hrefs.DERHref(
Expand All @@ -381,12 +394,37 @@ def initialize_2030_5(config: ServerConfiguration, tlsrepo: TLSRepository):
# raise ConfigurationError("default_program must be set to 'include_default_der_program_on_ders")
# der_obj.CurrentDERProgramLink = m.CurrentDERProgramLink(config.default_program.href)

derp: m.DERProgram = create_der_program_and_control(default_der_program=config.default_program,
default_der_control=config.default_der_control,
name=f"{der} Program")
derp, dderc = create_der_program_and_control(default_der_program=config.default_program,
default_der_control=config.default_der_control,
name=f"{der} Program")
der_obj.CurrentDERProgramLink = m.DERProgramLink(derp.href)

adpt.ListAdapter.append(ed_href.der_list, der_obj)
adpt.ListAdapter.set_single(obj=dderc, uri=dderc.href)
derp_derc_list_href = hrefs.SEP.join((derp.href, "derc"))
adpt.ListAdapter.initialize_uri(list_uri=derp_derc_list_href, obj=m.DERControl)
derp_derc: m.DERControl = m.DERControl(DERControlBase=dderc.DERControlBase)
adpt.ListAdapter.append(list_uri=derp_derc_list_href, obj=derp_derc)

adpt.ListAdapter.set_single(uri=derp_derc.href, obj=derp_derc)

if fsa_list := adpt.ListAdapter.get_list(ed_href.function_set_assignments):
# Create a new der program for this specific fsa
fsa: m.FunctionSetAssignments = fsa_list[0]
derp_fsa_href = hrefs.SEP.join((fsa.href, "derp"))
adpt.ListAdapter.initialize_uri(list_uri=derp_fsa_href, obj=m.DERProgram)
adpt.ListAdapter.append(list_uri=derp_fsa_href, obj=derp)
fsa.DERProgramListLink = m.DERProgramListLink(href=derp_fsa_href,
all=adpt.ListAdapter.list_size(derp_fsa_href))










current_min_primacy = 10000
current_der_program = None
try:
Expand Down

0 comments on commit 4522445

Please sign in to comment.