Skip to content

Commit

Permalink
feat: lockProvider uses LockRepository to send lock action
Browse files Browse the repository at this point in the history
  • Loading branch information
ses110 committed May 18, 2021
1 parent f80b2ab commit 8640b0f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/providers/lock_provider.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:yonomi_platform_sdk/repository/devices/devices_repository.dart';
import 'package:yonomi_platform_sdk/repository/devices/lock_repository.dart';
import 'package:yonomi_platform_sdk/request/request.dart';

class LockProvider extends ChangeNotifier {
bool loading = false;

LockProvider(Request request, String deviceId) {
_request = request;
getDeviceDetail(deviceId);
Expand All @@ -13,8 +16,17 @@ class LockProvider extends ChangeNotifier {

Device get deviceDetail => _deviceDetail;

bool get isLocked => _deviceDetail?.traits?.first?.state?.value ?? false;

Future<void> getDeviceDetail(String deviceId) async {
loading = true;
_deviceDetail = await DevicesRepository.getLockDetails(_request, deviceId);

loading = false;
notifyListeners();
}
}

Future<void> setLockUnlockAction(String deviceId, bool setLock) async {
await LockRepository.sendLockUnlockAction(_request, deviceId, setLock);
}
}

0 comments on commit 8640b0f

Please sign in to comment.