mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-20 07:25:06 +00:00
Improve property parsing
This commit is contained in:
parent
886aa70c39
commit
24cce1bd2a
@ -44,6 +44,7 @@ def parse_binding(file_path: str, binding_dirs: list[str]) -> Binding:
|
|||||||
type=details.get('type', 'unknown'),
|
type=details.get('type', 'unknown'),
|
||||||
required=details.get('required', False),
|
required=details.get('required', False),
|
||||||
description=details.get('description', '').strip(),
|
description=details.get('description', '').strip(),
|
||||||
|
default=details.get('default', None),
|
||||||
)
|
)
|
||||||
properties_dict[name] = prop
|
properties_dict[name] = prop
|
||||||
filename = os.path.basename(file_path)
|
filename = os.path.basename(file_path)
|
||||||
|
|||||||
@ -83,18 +83,37 @@ def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], de
|
|||||||
raise Exception(f"Binding not found for {device.node_name} and compatible '{compatible_property.value}'")
|
raise Exception(f"Binding not found for {device.node_name} and compatible '{compatible_property.value}'")
|
||||||
# Filter out system properties
|
# Filter out system properties
|
||||||
binding_properties = []
|
binding_properties = []
|
||||||
|
binding_property_names = set()
|
||||||
for property in device_binding.properties:
|
for property in device_binding.properties:
|
||||||
if property.name != "compatible":
|
if property.name != "compatible":
|
||||||
binding_properties.append(property)
|
binding_properties.append(property)
|
||||||
|
binding_property_names.add(property.name)
|
||||||
|
|
||||||
|
# Check for invalid properties in device
|
||||||
|
for device_property in device.properties:
|
||||||
|
if device_property.name in ["compatible"]:
|
||||||
|
continue
|
||||||
|
if device_property.name not in binding_property_names:
|
||||||
|
raise Exception(f"Device '{device.node_name}' has invalid property '{device_property.name}'")
|
||||||
|
|
||||||
# Allocate total expected configuration arguments
|
# Allocate total expected configuration arguments
|
||||||
result = [0] * len(binding_properties)
|
result = [0] * len(binding_properties)
|
||||||
for index, binding_property in enumerate(binding_properties):
|
for index, binding_property in enumerate(binding_properties):
|
||||||
device_property = find_device_property(device, binding_property.name)
|
device_property = find_device_property(device, binding_property.name)
|
||||||
if device_property is None:
|
if device_property is None:
|
||||||
if binding_property.required:
|
if binding_property.type == "bool":
|
||||||
|
result[index] = "false"
|
||||||
|
elif binding_property.required:
|
||||||
raise Exception(f"device {device.node_name} doesn't have property '{binding_property.name}'")
|
raise Exception(f"device {device.node_name} doesn't have property '{binding_property.name}'")
|
||||||
|
elif binding_property.default is not None:
|
||||||
|
temp_prop = DeviceProperty(
|
||||||
|
name=binding_property.name,
|
||||||
|
type=binding_property.type,
|
||||||
|
value=binding_property.default
|
||||||
|
)
|
||||||
|
result[index] = property_to_string(temp_prop, devices)
|
||||||
else:
|
else:
|
||||||
result[index] = '0'
|
raise Exception(f"Device {device.node_name} doesn't have property '{binding_property.name}' and no default value is set")
|
||||||
else:
|
else:
|
||||||
result[index] = property_to_string(device_property, devices)
|
result[index] = property_to_string(device_property, devices)
|
||||||
return result
|
return result
|
||||||
|
|||||||
@ -36,6 +36,7 @@ class BindingProperty:
|
|||||||
type: str
|
type: str
|
||||||
required: bool
|
required: bool
|
||||||
description: str
|
description: str
|
||||||
|
default: object = None
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Binding:
|
class Binding:
|
||||||
|
|||||||
@ -69,8 +69,6 @@
|
|||||||
|
|
||||||
## Lower Priority
|
## Lower Priority
|
||||||
|
|
||||||
- Rename `Lock::lock()` and `Lock::unlock()` to `Lock::acquire()` and `Lock::release()`?
|
|
||||||
- Implement system suspend that turns off the screen
|
|
||||||
- The boot button on some devices can be used as GPIO_NUM_0 at runtime
|
- The boot button on some devices can be used as GPIO_NUM_0 at runtime
|
||||||
- Localize all apps
|
- Localize all apps
|
||||||
- Support hot-plugging SD card (note: this is not possible if they require the CS pin hack)
|
- Support hot-plugging SD card (note: this is not possible if they require the CS pin hack)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user