Skip to content

Commit ebdff56

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

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 names:
5456
for name in names:
@@ -209,7 +211,7 @@ def _validate_reference(self, other: T, get_identifier: Callable[[Callable], str
209211

210212
# FIXME: in python 3.11, the IdentifiedObject type hint can be replaced with Self, and this can all be moved into the class def.
211213
# @singledispatchmethod
212-
def _validate_reference(self, other: IdentifiedObject | T, getter: Callable[[str], IdentifiedObject | T], type_description: Callable[[], str], get_identifier: Callable[[...], str]=None) -> bool:
214+
def _validate_reference(self, other: IdentifiedObject | T, getter: Callable[[str], IdentifiedObject | T], type_description: Callable[[], str] | str, get_identifier: Callable[[...], str]=None) -> bool:
213215
"""
214216
Validate whether a given reference exists to `other` using the provided getter function.
215217
@@ -221,18 +223,20 @@ def _validate_reference(self, other: IdentifiedObject | T, getter: Callable[[str
221223
"""
222224
if isinstance(other, IdentifiedObject):
223225
get_identifier = lambda _other: _other.mrid
224-
describe_other = f"{type_description} with mRID {other.mrid}"
226+
describe_other = lambda: f"{type_description} with mRID {other.mrid}"
225227
else:
226228
require(get_identifier is not None, lambda: "foo")
227229
describe_other = type_description
228-
229230
try:
230231
get_result = getter(get_identifier(other))
231-
require(get_result is other, lambda: f"{describe_other} already exists in {str(self)}")
232-
return True
233232
except (KeyError, AttributeError):
234233
return False
235234

235+
if get_result is other:
236+
return True
237+
238+
raise ValueError(f"{describe_other()} already exists in {str(self)}")
239+
236240
def _validate_reference_by_field(self, other: IdentifiedObject, field: Any, getter: Callable[[Any], IdentifiedObject],
237241
field_name: str) -> bool:
238242
"""

test/cim/cim_creators.py

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

749749

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)