Skip to content

Commit b3c25bd

Browse files
committed
DEV-835 moar changes
Signed-off-by: Max Chesterfield <max.chesterfield@zepben.com>
1 parent e82f07d commit b3c25bd

5 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/zepben/ewb/database/sqlite/network/network_cim_writer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ def _save_telephone_number(self, table: TableTelephoneNumbers, insert: PreparedS
10181018
insert.add_value(table.country_code.query_index, telephone_number.country_code)
10191019
insert.add_value(table.dial_out.query_index, telephone_number.dial_out)
10201020
insert.add_value(table.extension.query_index, telephone_number.extension)
1021+
insert.add_value(table.international_prefix.query_index, telephone_number.international_prefix)
10211022
insert.add_value(table.local_number.query_index, telephone_number.local_number)
10221023
insert.add_value(table.is_primary.query_index, telephone_number.is_primary)
10231024
insert.add_value(table.description.query_index, telephone_number.description)

src/zepben/ewb/model/cim/iec61968/metering/usage_point.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ def num_contacts(self):
201201

202202
def get_contact(self, _id: str) -> ContactDetails:
203203
"""All End devices at this usage point.""" # TODO: again, lol, also jvmsdk
204-
return get_by_mrid(self._contacts, _id)
204+
try:
205+
return next((it for it in self.contacts if it.id == _id))
206+
except StopIteration:
207+
raise KeyError(_id)
205208

206209
def add_contact(self, contact: ContactDetails) -> UsagePoint:
207210
"""Add a `ContactDetails` to this `UsagePoint`"""

src/zepben/ewb/model/cim/iec61970/base/core/identified_object.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"""
2525

2626
@dataclass(slots=True)
27-
class IdentifiedObject(object, metaclass=ABCMeta):
27+
class IdentifiedObject(metaclass=ABCMeta):
2828
"""
2929
Root class to provide common identification for all classes needing identification and naming attributes.
3030
Everything should extend this class, however it's not mandated that every subclass must use all the fields
@@ -49,6 +49,8 @@ class IdentifiedObject(object, metaclass=ABCMeta):
4949
# TODO: Missing num_diagram_objects: int = None def has_diagram_objects(self): return (self.num_diagram_objects or 0) > 0
5050

5151
def __init__(self, names: Optional[List[Name]] = None, **kwargs):
52+
if kwargs:
53+
raise TypeError("unexpected keyword arguments in IdentifiedObject constructor: {}".format(kwargs))
5254
super(IdentifiedObject, self).__init__(**kwargs)
5355
if not self.mrid or not self.mrid.strip():
5456
raise ValueError("You must provide an mRID for this object.")
@@ -212,7 +214,7 @@ def _validate_reference(self, other: T, get_identifier: Callable[[Callable], str
212214

213215
# FIXME: in python 3.11, the IdentifiedObject type hint can be replaced with Self, and this can all be moved into the class def.
214216
# @singledispatchmethod
215-
def _validate_reference(self, other: IdentifiedObject | T, getter: Callable[[str], IdentifiedObject | T], type_description: Callable[[], str], get_identifier: Callable[[...], str]=None) -> bool:
217+
def _validate_reference(self, other: IdentifiedObject | T, getter: Callable[[str], IdentifiedObject | T], type_description: Callable[[], str] | str, get_identifier: Callable[[...], str]=None) -> bool:
216218
"""
217219
Validate whether a given reference exists to `other` using the provided getter function.
218220
@@ -224,18 +226,20 @@ def _validate_reference(self, other: IdentifiedObject | T, getter: Callable[[str
224226
"""
225227
if isinstance(other, IdentifiedObject):
226228
get_identifier = lambda _other: _other.mrid
227-
describe_other = f"{type_description} with mRID {other.mrid}"
229+
describe_other = lambda: f"{type_description} with mRID {other.mrid}"
228230
else:
229231
require(get_identifier is not None, lambda: "foo")
230232
describe_other = type_description
231-
232233
try:
233234
get_result = getter(get_identifier(other))
234-
require(get_result is other, lambda: f"{describe_other} already exists in {str(self)}")
235-
return True
236235
except (KeyError, AttributeError):
237236
return False
238237

238+
if get_result is other:
239+
return True
240+
241+
raise ValueError(f"{describe_other()} already exists in {str(self)}")
242+
239243
def _validate_reference_by_field(self, other: IdentifiedObject, field: Any, getter: Callable[[Any], IdentifiedObject],
240244
field_name: str) -> bool:
241245
"""

test/cim/cim_creators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def create_relay_info(include_runtime: bool = True):
9393
def create_contact_details():
9494
return builds(
9595
ContactDetails,
96-
id=text(alphabet=ALPHANUM, max_size=TEXT_MAX_SIZE),
96+
id=text(alphabet=ALPHANUM, max_size=TEXT_MAX_SIZE, min_size=1),
9797
contact_address=create_street_address(),
9898
contact_type=one_of(none(), text(alphabet=ALPHANUM, max_size=TEXT_MAX_SIZE)),
9999
first_name=one_of(none(), text(alphabet=ALPHANUM, max_size=TEXT_MAX_SIZE)),
@@ -744,7 +744,7 @@ def create_usage_point(include_runtime: bool = True):
744744
approved_inverter_capacity=integers(min_value=MIN_32_BIT_INTEGER, max_value=MAX_32_BIT_INTEGER),
745745
equipment=lists(builds(EnergyConsumer, **create_identified_object(include_runtime)), max_size=2),
746746
end_devices=lists(builds(Meter, **create_identified_object(include_runtime)), max_size=2),
747-
contacts=lists(create_contact_details())
747+
contacts=lists(create_contact_details(), max_size=2)
748748
)
749749

750750

test/cim/iec61968/metering/test_usage_point.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ def test_contacts_collection():
131131
UsagePoint.remove_contact,
132132
UsagePoint.clear_contacts,
133133
lambda it: it.id,
134-
)
134+
)

0 commit comments

Comments
 (0)