fixes NumberSlider in lists, uses cache to infer current value type

This commit is contained in:
Mose Mueller 2024-05-06 09:45:19 +02:00
parent 6829d84997
commit 174dea0b33

View File

@ -108,25 +108,21 @@ class RPCInterface:
async def set_param(self, full_access_path: str, value: Any) -> None: async def set_param(self, full_access_path: str, value: Any) -> None:
path_parts = parse_full_access_path(full_access_path) path_parts = parse_full_access_path(full_access_path)
parent_object = get_object_by_path_parts(self._service, path_parts[:-1]) parent_object = get_object_by_path_parts(self._service, path_parts[:-1])
attr_name = path_parts[-1]
# I don't want to trigger the execution of a property getter as this might take current_value_dict = get_nested_dict_by_path(
# a while when connecting to remote devices self._state_manager.cache_value, full_access_path
if not isinstance( )
getattr(type(parent_object), attr_name, None), if "Enum" in current_value_dict["type"] and isinstance(value, int):
property, # Ionizer sets the enums using the position of the definition order.
): # The following works as definition order is kept, see e.g.
current_value = getattr(parent_object, attr_name, None) # https://docs.python.org/3/library/enum.html#enum.EnumType.__iter__
if isinstance(current_value, Enum) and isinstance(value, int): current_value = get_object_by_path_parts(parent_object, [path_parts[-1]])
# Ionizer sets the enums using the position of the definition order value = list(current_value.__class__)[value]
# This works as definition order is kept, see e.g. if current_value_dict["type"] == "Quantity":
# https://docs.python.org/3/library/enum.html#enum.EnumType.__iter__ current_value = get_object_by_path_parts(parent_object, [path_parts[-1]])
# I need to use the name attribute as this is what value = value * current_value.u
# DataService.__set_attribute_based_on_type expects elif current_value_dict["type"] == "NumberSlider":
value = list(current_value.__class__)[value] full_access_path = full_access_path + ".value"
if isinstance(current_value, Quantity):
value = value * current_value.u
elif isinstance(current_value, NumberSlider):
full_access_path = full_access_path + ".value"
self._state_manager.set_service_attribute_value_by_path( self._state_manager.set_service_attribute_value_by_path(
full_access_path, dump(value) full_access_path, dump(value)