Coverage for backend/django/idaes_factory/adapters/toggle_adapter.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-05-13 02:47 +0000

1from ahuora_builder_types.unit_model_schema import ValueArgSchema 

2 

3from .property_info_adapter import ValueAdapter 

4from ..queryset_lookup import get_property, get_value_object 

5from ahuora_builder_types import PropertySchema, PropertiesSchema, PropertyValueSchema 

6 

7 

8class ToggleAdapter(ValueAdapter): 

9 """ 

10 Returns True if the unit model has dynamics enabled, otherwise False. 

11 """ 

12 def __init__(self, toggle_key:str): 

13 self.toggle_key = toggle_key 

14 

15 def serialise(self, ctx, model) -> bool: 

16 

17 # get the property from the unit model 

18 property_set = model.properties 

19 prop = get_property(property_set, self.toggle_key) 

20 # serialise the property 

21 return ValueArgSchema(value=prop.values.first().value == True)