Loading files
import 'package:lw_wot/property.dart';
import 'package:lw_wot/thing.dart';
import 'package:lw_wot/value.dart';
enum DeviceMode {
off,
on,
standby;
@override
String toString() => name;
static List<String> get allValues => values.map((e) => e.name).toList();
}
void main() {
print('Enum Property Example for lw_wot');
// 创建设备
final device = WotThing(
id: 'test-device',
title: 'Test Device',
type: ['TestDevice'],
description: 'A test device with enum property',
);
// 创建枚举属性
final modeProperty = WotProperty<String>(
thing: device,
name: 'mode',
value: WotValue<String>(initialValue: DeviceMode.off.toString()),
metadata: WotPropertyMetadata(
type: 'string',
title: 'Device Mode',
description: 'Current mode of the device',
enumValues: DeviceMode.allValues,
readOnly: false,
),
);
device.addProperty(modeProperty);
print('Initial mode: ${modeProperty.getValue()}');
print('Available modes: ${DeviceMode.allValues}');
// 修改属性值
modeProperty.setValue(DeviceMode.on.toString());
print('Mode changed to: ${modeProperty.getValue()}');
// 显示属性描述
final desc = modeProperty.asPropertyDescription();
print('Property description:');
print(' Type: ${desc['type']}');
print(' Enum values: ${desc['enum']}');
print(' Read only: ${desc['readOnly']}');
print('Enum property example completed successfully!');
}
8c2908ee5This file is pinned to the selected release. Download the original to open it in your design tool.