-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from guyluz11/dev
Add files for xiaomi #57 and closed #59
- Loading branch information
Showing
18 changed files
with
376 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...hue/philips_hue_device_value_objects.dart → ...hue/philips_hue_device_value_objects.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ices/philips hue/philips_hue_helpers.dart → ...ices/philips_hue/philips_hue_helpers.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
lib/infrastructure/devices/xiaomi_io/xiaomi_io_connector_conjector.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:cbj_hub/domain/generic_devices/abstract_device/core_failures.dart'; | ||
import 'package:cbj_hub/domain/generic_devices/abstract_device/device_entity_abstract.dart'; | ||
import 'package:cbj_hub/infrastructure/devices/xiaomi_io/xiaomi_io_gpx3021gl/xiaomi_io_gpx3021gl_entity.dart'; | ||
import 'package:cbj_hub/infrastructure/generic_devices/abstract_device/abstract_company_connector_conjector.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
|
||
@singleton | ||
class XiaomiIoConnectorConjector implements AbstractCompanyConnectorConjector { | ||
XiaomiIoConnectorConjector() { | ||
_discoverNewDevices(); | ||
} | ||
|
||
@override | ||
static Map<String, DeviceEntityAbstract> companyDevices = {}; | ||
|
||
Future<void> _discoverNewDevices() async { | ||
// await MiIoCommandRunner().run(args); | ||
// final InternetAddress internetAddress = InternetAddress('192.168.31.255'); | ||
// final MiIo miIo = MiIo.instance; | ||
// miIo.discover(internetAddress).listen((event) { | ||
// print('event $event'); | ||
// }); | ||
// MiIo m = MiIo(); | ||
// MiIoDevice miDevice = MiIoDevice(address: internetAddress); | ||
// miio discover --ip 192.168.1.255 | ||
} | ||
|
||
@override | ||
Future<Either<CoreFailure, Unit>> create(DeviceEntityAbstract xiaomi_io) { | ||
// TODO: implement create | ||
throw UnimplementedError(); | ||
} | ||
|
||
@override | ||
Future<Either<CoreFailure, Unit>> delete(DeviceEntityAbstract xiaomi_io) { | ||
// TODO: implement delete | ||
throw UnimplementedError(); | ||
} | ||
|
||
@override | ||
Future<void> initiateHubConnection() { | ||
// TODO: implement initiateHubConnection | ||
throw UnimplementedError(); | ||
} | ||
|
||
@override | ||
Future<void> manageHubRequestsForDevice( | ||
DeviceEntityAbstract xiaomiDE, | ||
) async { | ||
final DeviceEntityAbstract? device = companyDevices[xiaomiDE.getDeviceId()]; | ||
|
||
if (device is XiaomiIoGpx4021GlEntity) { | ||
device.executeDeviceAction(xiaomiDE); | ||
} else { | ||
print('XiaomiIo device type does not exist'); | ||
} | ||
} | ||
|
||
@override | ||
Future<Either<CoreFailure, Unit>> updateDatabase( | ||
{required String pathOfField, | ||
required Map<String, dynamic> fieldsToUpdate, | ||
String? forceUpdateLocation}) async { | ||
// TODO: implement updateDatabase | ||
throw UnimplementedError(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
lib/infrastructure/devices/xiaomi_io/xiaomi_io_device_validators.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:cbj_hub/domain/generic_devices/abstract_device/core_failures.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
|
||
Either<CoreFailure<String>, String> validateXiaomiIoIdNotEmpty(String input) { | ||
if (input != null) { | ||
return right(input); | ||
} else { | ||
return left(CoreFailure.empty(failedValue: input)); | ||
} | ||
} | ||
|
||
Either<CoreFailure<String>, String> validateXiaomiIoPortNotEmpty( | ||
String input, | ||
) { | ||
if (input != null) { | ||
return right(input); | ||
} else { | ||
return left(CoreFailure.empty(failedValue: input)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
lib/infrastructure/devices/xiaomi_io/xiaomi_io_device_value_objects.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:cbj_hub/domain/generic_devices/abstract_device/core_failures.dart'; | ||
import 'package:cbj_hub/domain/generic_devices/abstract_device/value_objects_core.dart'; | ||
import 'package:cbj_hub/infrastructure/devices/xiaomi_io/xiaomi_io_device_validators.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
|
||
/// XiaomiIo device unique address that came withe the device | ||
class XiaomiIoDeviceId extends ValueObjectCore<String> { | ||
factory XiaomiIoDeviceId(String? input) { | ||
assert(input != null); | ||
return XiaomiIoDeviceId._( | ||
validateXiaomiIoIdNotEmpty(input!), | ||
); | ||
} | ||
|
||
const XiaomiIoDeviceId._(this.value); | ||
|
||
@override | ||
final Either<CoreFailure<String>, String> value; | ||
} | ||
|
||
/// XiaomiIo communication port | ||
class XiaomiIoPort extends ValueObjectCore<String> { | ||
factory XiaomiIoPort(String? input) { | ||
assert(input != null); | ||
return XiaomiIoPort._( | ||
validateXiaomiIoPortNotEmpty(input!), | ||
); | ||
} | ||
|
||
const XiaomiIoPort._(this.value); | ||
|
||
@override | ||
final Either<CoreFailure<String>, String> value; | ||
} |
158 changes: 158 additions & 0 deletions
158
lib/infrastructure/devices/xiaomi_io/xiaomi_io_gpx3021gl/xiaomi_io_gpx3021gl_entity.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:cbj_hub/domain/generic_devices/abstract_device/core_failures.dart'; | ||
import 'package:cbj_hub/domain/generic_devices/abstract_device/device_entity_abstract.dart'; | ||
import 'package:cbj_hub/domain/generic_devices/abstract_device/value_objects_core.dart'; | ||
import 'package:cbj_hub/domain/generic_devices/device_type_enums.dart'; | ||
import 'package:cbj_hub/domain/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; | ||
import 'package:cbj_hub/domain/generic_devices/generic_rgbw_light_device/generic_rgbw_light_value_objects.dart'; | ||
import 'package:cbj_hub/infrastructure/devices/xiaomi_io/xiaomi_io_device_value_objects.dart'; | ||
import 'package:cbj_hub/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:yeedart/yeedart.dart'; | ||
|
||
class XiaomiIoGpx4021GlEntity extends GenericRgbwLightDE { | ||
XiaomiIoGpx4021GlEntity({ | ||
required CoreUniqueId uniqueId, | ||
required CoreUniqueId roomId, | ||
required DeviceDefaultName defaultName, | ||
required DeviceRoomName roomName, | ||
required DeviceState deviceStateGRPC, | ||
required DeviceStateMassage stateMassage, | ||
required DeviceSenderDeviceOs senderDeviceOs, | ||
required DeviceSenderDeviceModel senderDeviceModel, | ||
required DeviceSenderId senderId, | ||
required DeviceCompUuid compUuid, | ||
required DevicePowerConsumption powerConsumption, | ||
required GenericRgbwLightSwitchState lightSwitchState, | ||
required GenericRgbwLightColorAlpha lightColorAlpha, | ||
required GenericRgbwLightColorHue lightColorHue, | ||
required GenericRgbwLightColorSaturation lightColorSaturation, | ||
required GenericRgbwLightColorValue lightColorValue, | ||
required this.xiaomi_ioDeviceId, | ||
required this.xiaomi_ioPort, | ||
this.deviceMdnsName, | ||
this.lastKnownIp, | ||
required GenericRgbwLightColorTemperature lightColorTemperature, | ||
required GenericRgbwLightBrightness lightBrightness, | ||
}) : super( | ||
uniqueId: uniqueId, | ||
defaultName: defaultName, | ||
roomId: roomId, | ||
lightSwitchState: lightSwitchState, | ||
roomName: roomName, | ||
deviceStateGRPC: deviceStateGRPC, | ||
stateMassage: stateMassage, | ||
senderDeviceOs: senderDeviceOs, | ||
senderDeviceModel: senderDeviceModel, | ||
senderId: senderId, | ||
// TODO: change when implementing philips hue | ||
deviceVendor: DeviceVendor( | ||
VendorsAndServices.vendorsAndServicesNotSupported.toString()), | ||
compUuid: compUuid, | ||
powerConsumption: powerConsumption, | ||
lightColorTemperature: lightColorTemperature, | ||
lightBrightness: lightBrightness, | ||
lightColorAlpha: lightColorAlpha, | ||
lightColorHue: lightColorHue, | ||
lightColorSaturation: lightColorSaturation, | ||
lightColorValue: lightColorValue, | ||
); | ||
|
||
/// XiaomiIo device unique id that came withe the device | ||
XiaomiIoDeviceId? xiaomi_ioDeviceId; | ||
|
||
/// XiaomiIo communication port | ||
XiaomiIoPort? xiaomi_ioPort; | ||
|
||
DeviceLastKnownIp? lastKnownIp; | ||
|
||
DeviceMdnsName? deviceMdnsName; | ||
|
||
/// XiaomiIo package object require to close previews request before new one | ||
Device? xiaomi_ioPackageObject; | ||
|
||
/// Please override the following methods | ||
@override | ||
Future<Either<CoreFailure, Unit>> executeDeviceAction( | ||
DeviceEntityAbstract newEntity, | ||
) async { | ||
if (newEntity is! GenericRgbwLightDE) { | ||
return left( | ||
const CoreFailure.actionExcecuter( | ||
failedValue: 'Not the correct type', | ||
), | ||
); | ||
} | ||
|
||
if (newEntity.lightSwitchState!.getOrCrash() != | ||
lightSwitchState!.getOrCrash()) { | ||
final DeviceActions? actionToPreform = EnumHelper.stringToDeviceAction( | ||
newEntity.lightSwitchState!.getOrCrash(), | ||
); | ||
|
||
if (actionToPreform.toString() != lightSwitchState!.getOrCrash()) { | ||
if (actionToPreform == DeviceActions.on) { | ||
(await turnOnLight()).fold( | ||
(l) => print('Error turning xiaomi_io light on'), | ||
(r) => print('Light turn on success')); | ||
} else if (actionToPreform == DeviceActions.off) { | ||
(await turnOffLight()).fold( | ||
(l) => print('Error turning xiaomi_io light off'), | ||
(r) => print('Light turn off success'), | ||
); | ||
} else { | ||
print('actionToPreform is not set correctly on XiaomiIo Gpx4021Gl'); | ||
} | ||
} | ||
} | ||
|
||
return right(unit); | ||
} | ||
|
||
@override | ||
Future<Either<CoreFailure, Unit>> turnOnLight() async { | ||
lightSwitchState = GenericRgbwLightSwitchState(DeviceActions.on.toString()); | ||
try { | ||
return left(const CoreFailure.unexpected()); | ||
} catch (e) { | ||
return left(const CoreFailure.unexpected()); | ||
} | ||
} | ||
|
||
@override | ||
Future<Either<CoreFailure, Unit>> turnOffLight() async { | ||
lightSwitchState = | ||
GenericRgbwLightSwitchState(DeviceActions.off.toString()); | ||
try { | ||
return left(const CoreFailure.unexpected()); | ||
} catch (e) { | ||
return left(const CoreFailure.unexpected()); | ||
} | ||
} | ||
|
||
@override | ||
Future<Either<CoreFailure, Unit>> adjustBrightness(String brightness) async { | ||
print('Please override this method in the non generic implementation'); | ||
return left( | ||
const CoreFailure.actionExcecuter( | ||
failedValue: 'Action does not exist', | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Future<Either<CoreFailure, Unit>> changeColorTemperature({ | ||
required String lightColorAlphaNewValue, | ||
required String lightColorHueNewValue, | ||
required String lightColorSaturationNewValue, | ||
required String lightColorValueNewValue, | ||
}) async { | ||
print('Please override this method in the non generic implementation'); | ||
return left( | ||
const CoreFailure.actionExcecuter( | ||
failedValue: 'Action does not exist', | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.