el_webapi_api 0.0.1+1
el_webapi_api: ^0.0.1+1 copied to clipboard
A library to interact with ECHONET Lite Web API (v1.3.0). It uses http.Client library and supports parse returned data into corresponding objects.
example/main.dart
import 'package:el_webapi_api/src/el_webapi_client.dart';
import 'package:el_webapi_api/src/models/models.dart';
void main() async {
const accessToken = 'accessToken';
const serverUrl = 'serverURL';
final ElWebApiClient client = ElWebApiClient(url: serverUrl, header: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $accessToken',
});
/// Get registered devices
/// Request uri: xxx/elapi/v1/devices
/// Response { devices[profile1,...], hasMore, limit, offset}
/// Profile = {id, deviceType, manufacturer, protocol}
final RegisteredDeviceList devList = await client.getRegisteredDevices();
for (final Profile profile in devList.profiles) {
print(profile.toJson());
/// Result
///
}
final List<EchonetLiteDevice>? devices =
await client.fetchRegisteredDevicesResources(null);
if (devices != null) {
print(devices.length);
for (final EchonetLiteDevice dev in devices) {
if (dev.runtimeType == TemperatureSensor) {
final TemperatureSensor temperatureSensor = dev as TemperatureSensor;
// print(temperatureSensor.toJson());
}
}
} else {
print('no thing');
}
final List<EchonetLiteDevice>? temperatureSensors =
await client.getDeviceResourcesByType(DeviceType.temperatureSensor, null);
if (temperatureSensors != null) {
for (final EchonetLiteDevice sensor in temperatureSensors) {
final TemperatureSensor temperatureSensor = sensor as TemperatureSensor;
//print(temperatureSensor.toJson());
}
}
final TemperatureSensor? sensor =
await client.getTemperatureSensor('temperatureSensor1653899075894947');
//print(sensor.toJson());
bool setResult =
await client.setOperationStatus('generalLighting1653899076208582', false);
// Or
bool setResult2 = await client.setPropertyNameWithValue(
'generalLighting1653899076208582', 'operationStatus', false);
}