diff --git a/.gitignore b/.gitignore index 8bc7012e..08f3134d 100644 --- a/.gitignore +++ b/.gitignore @@ -90,4 +90,7 @@ saved_cast_state.json lib/infrastructure/core/constant_credentials.dart # Web related -lib/generated_plugin_registrant.dart \ No newline at end of file +lib/generated_plugin_registrant.dart + +# Network tools +network_tools_db/* \ No newline at end of file diff --git a/bin/cbj_hub.dart b/bin/cbj_hub.dart index 1d18d266..96590e6c 100644 --- a/bin/cbj_hub.dart +++ b/bin/cbj_hub.dart @@ -6,9 +6,11 @@ import 'package:cbj_hub/infrastructure/shared_variables.dart'; import 'package:cbj_hub/infrastructure/system_commands/device_pin_manager.dart'; import 'package:cbj_hub/injection.dart'; import 'package:cbj_hub/utils.dart'; +import 'package:network_tools/network_tools.dart'; Future main(List arguments) async { // arguments[0] is the location of the project + configureNetworkTools('network_tools_db'); configureInjection(Env.prod); try { diff --git a/lib/infrastructure/devices/companies_connector_conjector.dart b/lib/infrastructure/devices/companies_connector_conjector.dart index ea983398..86ad5723 100644 --- a/lib/infrastructure/devices/companies_connector_conjector.dart +++ b/lib/infrastructure/devices/companies_connector_conjector.dart @@ -21,7 +21,6 @@ import 'package:cbj_hub/infrastructure/devices/lifx/lifx_connector_conjector.dar import 'package:cbj_hub/infrastructure/devices/philips_hue/philips_hue_connector_conjector.dart'; import 'package:cbj_hub/infrastructure/devices/shelly/shelly_connector_conjector.dart'; import 'package:cbj_hub/infrastructure/devices/sonoff_diy/sonoff_diy_connector_conjector.dart'; -import 'package:cbj_hub/infrastructure/devices/switcher/switcher_api/switcher_discover.dart'; import 'package:cbj_hub/infrastructure/devices/switcher/switcher_connector_conjector.dart'; import 'package:cbj_hub/infrastructure/devices/tasmota/tasmota_ip/tasmota_ip_connector_conjector.dart'; import 'package:cbj_hub/infrastructure/devices/tuya_smart/tuya_smart_connector_conjector.dart'; @@ -35,6 +34,7 @@ import 'package:cbj_hub/injection.dart'; import 'package:cbj_hub/utils.dart'; import 'package:internet_connection_checker/internet_connection_checker.dart'; import 'package:network_tools/network_tools.dart'; +import 'package:switcher_dart/switcher_dart.dart'; class CompaniesConnectorConjector { static void updateAllDevicesReposWithDeviceChanges( diff --git a/lib/infrastructure/devices/esphome/esphome_helpers.dart b/lib/infrastructure/devices/esphome/esphome_helpers.dart index 4c4ee3f5..4b23282c 100644 --- a/lib/infrastructure/devices/esphome/esphome_helpers.dart +++ b/lib/infrastructure/devices/esphome/esphome_helpers.dart @@ -52,7 +52,7 @@ class EspHomeHelpers { return tempEspHomeNodeDeviceId; } - static Future> retreveOnlyNewEntities({ + static Future> retrieveOnlyNewEntities({ required String mDnsName, required String devicePassword, String? espHomeDeviceNodeId, @@ -98,7 +98,7 @@ class EspHomeHelpers { /// Make sure we add only new entities final List entitiesList = - await retreveOnlyNewEntities( + await retrieveOnlyNewEntities( mDnsName: mDnsName, devicePassword: devicePassword, espHomeDeviceNodeId: espHomeDeviceNodeId, @@ -111,12 +111,13 @@ class EspHomeHelpers { final List deviceEntityList = []; final EspHomeNodeRedApi espHomeNodeRedApi = EspHomeNodeRedApi( - repository: getIt(), - nodeRedApiBaseTopic: - getIt().getNodeRedApiBaseTopic(), - nodeRedDevicesTopic: - getIt().getNodeRedDevicesTopicTypeName(), - nodeRedMqttBrokerNodeName: 'Cbj NodeRed plugs Api Broker'); + repository: getIt(), + nodeRedApiBaseTopic: + getIt().getNodeRedApiBaseTopic(), + nodeRedDevicesTopic: + getIt().getNodeRedDevicesTopicTypeName(), + nodeRedMqttBrokerNodeName: 'Cbj NodeRed plugs Api Broker', + ); for (final EspHomeDeviceEntityObject espHomeDeviceEntityObject in entitiesList) { diff --git a/lib/infrastructure/devices/ewelink/ewelink_connector_conjector.dart b/lib/infrastructure/devices/ewelink/ewelink_connector_conjector.dart index 82ffd4d0..f70f50f2 100644 --- a/lib/infrastructure/devices/ewelink/ewelink_connector_conjector.dart +++ b/lib/infrastructure/devices/ewelink/ewelink_connector_conjector.dart @@ -22,7 +22,7 @@ class EwelinkConnectorConjector implements AbstractCompanyConnectorConjector { @override Map companyDevices = {}; - Future accountLogin( + Future accountLogin( GenericEwelinkLoginDE loginDE, ) async { try { @@ -32,27 +32,31 @@ class EwelinkConnectorConjector implements AbstractCompanyConnectorConjector { ); await ewelink!.getCredentials(); - discoverNewDevices(activeHost: null); } on EwelinkInvalidAccessToken { logger.e('invalid access token'); + return false; } on EwelinkOfflineDeviceException { logger.e('device is offline'); + return false; } catch (e) { - // ignore: unnecessary_brace_in_string_interps - logger.e('error: $e'); + logger.e('EweLink error: $e'); + return false; } - return 'Success'; + return true; } Future discoverNewDevices({ required ActiveHost? activeHost, }) async { if (ewelink == null) { - await accountLogin(GenericEwelinkLoginDE.empty()); - logger.w( - 'eWeLink device got found but missing a email and password, please add ' - 'it in the app'); - // return; + final bool lastRequest = + await accountLogin(GenericEwelinkLoginDE.empty()); + if (!lastRequest) { + logger.w( + 'eWeLink device got found but missing a email and password, please add ' + 'it in the app'); + return; + } } final List devices = await ewelink!.getDevices(); diff --git a/lib/infrastructure/devices/shelly/shelly_api/shelly_api_color_bulb.dart b/lib/infrastructure/devices/shelly/shelly_api/shelly_api_color_bulb.dart deleted file mode 100644 index 38a0e58c..00000000 --- a/lib/infrastructure/devices/shelly/shelly_api/shelly_api_color_bulb.dart +++ /dev/null @@ -1,124 +0,0 @@ -import 'dart:io'; - -import 'package:cbj_hub/infrastructure/devices/shelly/shelly_api/shelly_api_device_abstract.dart'; - -class ShellyApiColorBulb extends ShellyApiDeviceAbstract { - ShellyApiColorBulb({ - required super.lastKnownIp, - required super.mDnsName, - required super.hostName, - this.bulbeMode = ShellyBulbeMode.white, - }); - - // The mod of the bulb, an be white or color - ShellyBulbeMode bulbeMode; - - Future turnOn() async { - final HttpClientRequest httpClientRequest = - await HttpClient().getUrl(Uri.parse('$url/color/0?turn=on')); - final HttpClientResponse response = await httpClientRequest.close(); - - return response.reasonPhrase; - } - - Future turnOff() async { - final HttpClientRequest httpClientRequest = - await HttpClient().getUrl(Uri.parse('$url/color/0?turn=off')); - final HttpClientResponse response = await httpClientRequest.close(); - - return response.reasonPhrase; - } - - Future changeModeToWhite() async { - bulbeMode = ShellyBulbeMode.white; - final HttpClientRequest httpClientRequest = - await HttpClient().getUrl(Uri.parse('$url/settings/?mode=white')); - final HttpClientResponse response = await httpClientRequest.close(); - - return response.reasonPhrase; - } - - Future changeModeToColor() async { - bulbeMode = ShellyBulbeMode.colore; - final HttpClientRequest httpClientRequest = - await HttpClient().getUrl(Uri.parse('$url/settings/?mode=color')); - final HttpClientResponse response = await httpClientRequest.close(); - - return response.reasonPhrase; - } - - /// Changing brightness alone called gain and it is 0-100. - /// I think works only on color mode - Future changeBrightnessColorGain(String brightness) async { - final HttpClientRequest httpClientRequest = await HttpClient() - .getUrl(Uri.parse('$url/color/0?turn=on&gain=$brightness')); - final HttpClientResponse response = await httpClientRequest.close(); - return response.reasonPhrase; - } - - /// Change temperature - Future changTemperature({ - required String temperature, - }) async { - if (bulbeMode != ShellyBulbeMode.white) { - await changeModeToWhite(); - } - - final HttpClientRequest httpClientRequest = await HttpClient().getUrl( - Uri.parse( - '$url/color/0?turn=on&temp=$temperature', - ), - ); - final HttpClientResponse response = await httpClientRequest.close(); - return response.reasonPhrase; - } - - /// Chang brightness - Future changBrightness({ - required String brightness, - }) async { - HttpClientRequest httpClientRequest; - - switch (bulbeMode) { - case ShellyBulbeMode.white: - httpClientRequest = await HttpClient().getUrl( - Uri.parse( - '$url/color/0?turn=on&brightness=$brightness', - ), - ); - break; - case ShellyBulbeMode.colore: - httpClientRequest = await HttpClient().getUrl( - Uri.parse( - '$url/color/0?turn=on&gain=$brightness', - ), - ); - break; - } - - final HttpClientResponse response = await httpClientRequest.close(); - return response.reasonPhrase; - } - - /// Change color of the bulb, I think will also change to color mode - Future changeColor({ - required String red, - required String green, - required String blue, - String white = "0", - }) async { - if (bulbeMode != ShellyBulbeMode.colore) { - await changeModeToColor(); - } - - final HttpClientRequest httpClientRequest = await HttpClient().getUrl( - Uri.parse( - '$url/color/0?turn=on&red=$red&green=$green&blue=$blue&white=$white', - ), - ); - final HttpClientResponse response = await httpClientRequest.close(); - return response.reasonPhrase; - } -} - -enum ShellyBulbeMode { white, colore } diff --git a/lib/infrastructure/devices/shelly/shelly_api/shelly_api_device_abstract.dart b/lib/infrastructure/devices/shelly/shelly_api/shelly_api_device_abstract.dart deleted file mode 100644 index b9fed522..00000000 --- a/lib/infrastructure/devices/shelly/shelly_api/shelly_api_device_abstract.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:http/http.dart'; - -abstract class ShellyApiDeviceAbstract { - ShellyApiDeviceAbstract({ - required this.lastKnownIp, - required this.mDnsName, - required this.hostName, - this.name, - }) { - url = 'http://$lastKnownIp'; - } - - String lastKnownIp; - String mDnsName; - String hostName; - String? name; - late String url; - - Future getStatus() async { - final Response response = await get(Uri.parse('$url/status')); - - return response.body; - } -} diff --git a/lib/infrastructure/devices/shelly/shelly_api/shelly_api_relay_switch.dart b/lib/infrastructure/devices/shelly/shelly_api/shelly_api_relay_switch.dart deleted file mode 100644 index a20c27ee..00000000 --- a/lib/infrastructure/devices/shelly/shelly_api/shelly_api_relay_switch.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'dart:io'; - -import 'package:cbj_hub/infrastructure/devices/shelly/shelly_api/shelly_api_device_abstract.dart'; - -class ShellyApiRelaySwitch extends ShellyApiDeviceAbstract { - ShellyApiRelaySwitch({ - required super.lastKnownIp, - required super.mDnsName, - required super.hostName, - }); - - Future turnOn() async { - final HttpClientRequest httpClientRequest = - await HttpClient().getUrl(Uri.parse('$url/relay/0?turn=on')); - final HttpClientResponse response = await httpClientRequest.close(); - - return response.reasonPhrase; - } - - Future turnOff() async { - final HttpClientRequest httpClientRequest = - await HttpClient().getUrl(Uri.parse('$url/relay/0?turn=off')); - final HttpClientResponse response = await httpClientRequest.close(); - - return response.reasonPhrase; - } -} diff --git a/lib/infrastructure/devices/shelly/shelly_connector_conjector.dart b/lib/infrastructure/devices/shelly/shelly_connector_conjector.dart index 50d4f8fa..84f04444 100644 --- a/lib/infrastructure/devices/shelly/shelly_connector_conjector.dart +++ b/lib/infrastructure/devices/shelly/shelly_connector_conjector.dart @@ -45,7 +45,7 @@ class ShellyConnectorConjector implements AbstractCompanyConnectorConjector { } } - final List espDevice = + final List shellyDevice = await ShellyHelpers.addDiscoverdDevice( mDnsName: mDnsName, ip: ip, @@ -53,11 +53,11 @@ class ShellyConnectorConjector implements AbstractCompanyConnectorConjector { uniqueDeviceId: tempCoreUniqueId, ); - if (espDevice.isEmpty) { + if (shellyDevice.isEmpty) { return; } - for (final DeviceEntityAbstract entityAsDevice in espDevice) { + for (final DeviceEntityAbstract entityAsDevice in shellyDevice) { final DeviceEntityAbstract deviceToAdd = CompaniesConnectorConjector.addDiscoverdDeviceToHub(entityAsDevice); diff --git a/lib/infrastructure/devices/shelly/shelly_helpers.dart b/lib/infrastructure/devices/shelly/shelly_helpers.dart index 415b9086..d7ddbc88 100644 --- a/lib/infrastructure/devices/shelly/shelly_helpers.dart +++ b/lib/infrastructure/devices/shelly/shelly_helpers.dart @@ -4,12 +4,12 @@ import 'package:cbj_hub/domain/generic_devices/abstract_device/device_entity_abs import 'package:cbj_hub/domain/generic_devices/abstract_device/value_objects_core.dart'; import 'package:cbj_hub/domain/generic_devices/generic_rgbw_light_device/generic_rgbw_light_value_objects.dart'; import 'package:cbj_hub/domain/generic_devices/generic_switch_device/generic_switch_value_objects.dart'; -import 'package:cbj_hub/infrastructure/devices/shelly/shelly_api/shelly_api_color_bulb.dart'; import 'package:cbj_hub/infrastructure/devices/shelly/shelly_light/shelly_light_entity.dart'; import 'package:cbj_hub/infrastructure/devices/shelly/shelly_relay_switch/shelly_relay_switch_entity.dart'; import 'package:cbj_hub/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbenum.dart'; import 'package:cbj_hub/utils.dart'; import 'package:color/color.dart'; +import 'package:shelly/shelly.dart'; class ShellyHelpers { static Future> addDiscoverdDevice({ @@ -28,7 +28,7 @@ class ShellyHelpers { final List deviceEntityList = []; try { - // TODO: shelly duo bulbe needs type that as the time of writing is + // TODO: shelly duo bulb needs type that as the time of writing is // not supported, bulb + brightness + white temperature (not rgb). // Lets create new type and add it. if (mDnsName.contains('colorbulb')) { @@ -46,14 +46,14 @@ class ShellyHelpers { dynamic bulbLightProp = responseAsJson['lights'][0]; final String bulbMod = bulbLightProp['mode'] as String; - shellyApiDeviceAbstract.bulbeMode = - bulbMod == 'color' ? ShellyBulbeMode.colore : ShellyBulbeMode.white; + shellyApiDeviceAbstract.bulbMode = + bulbMod == 'color' ? ShellyBulbMode.colore : ShellyBulbMode.white; final int brightness = bulbLightProp['brightness'] as int; final int gain = bulbLightProp['gain'] as int; // Brightness for color mod final int currentBrightness = - shellyApiDeviceAbstract.bulbeMode == ShellyBulbeMode.colore + shellyApiDeviceAbstract.bulbMode == ShellyBulbMode.colore ? gain : brightness; final int temp = bulbLightProp['temp'] as int; @@ -95,7 +95,7 @@ class ShellyHelpers { deviceHostName: DeviceHostName(mDnsName.toLowerCase()), deviceMdns: DeviceMdns(mDnsName), deviceLastKnownIp: DeviceLastKnownIp(ip), - bulbeMode: shellyApiDeviceAbstract, + bulbMode: shellyApiDeviceAbstract, deviceUniqueId: DeviceUniqueId('0'), devicesMacAddress: DevicesMacAddress('0'), entityKey: EntityKey('0'), @@ -118,7 +118,7 @@ class ShellyHelpers { dynamic bulbLightProp = responseAsJson['lights'][0]; - shellyApiDeviceAbstract.bulbeMode = ShellyBulbeMode.white; + shellyApiDeviceAbstract.bulbMode = ShellyBulbMode.white; final int brightness = bulbLightProp['brightness'] as int; @@ -155,7 +155,7 @@ class ShellyHelpers { deviceHostName: DeviceHostName(mDnsName.toLowerCase()), deviceMdns: DeviceMdns(mDnsName), deviceLastKnownIp: DeviceLastKnownIp(ip), - bulbeMode: shellyApiDeviceAbstract, + bulbMode: shellyApiDeviceAbstract, deviceUniqueId: DeviceUniqueId('0'), devicesMacAddress: DevicesMacAddress('0'), entityKey: EntityKey('0'), diff --git a/lib/infrastructure/devices/shelly/shelly_light/shelly_light_entity.dart b/lib/infrastructure/devices/shelly/shelly_light/shelly_light_entity.dart index a8ca0693..c832b82d 100644 --- a/lib/infrastructure/devices/shelly/shelly_light/shelly_light_entity.dart +++ b/lib/infrastructure/devices/shelly/shelly_light/shelly_light_entity.dart @@ -4,11 +4,11 @@ import 'package:cbj_hub/domain/generic_devices/abstract_device/value_objects_cor 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/shelly/shelly_api/shelly_api_color_bulb.dart'; import 'package:cbj_hub/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_hub/utils.dart'; import 'package:color/color.dart'; import 'package:dartz/dartz.dart'; +import 'package:shelly/shelly.dart'; class ShellyColorLightEntity extends GenericRgbwLightDE { ShellyColorLightEntity({ @@ -41,11 +41,11 @@ class ShellyColorLightEntity extends GenericRgbwLightDE { required super.lightColorSaturation, required super.lightColorValue, required super.lightBrightness, - ShellyApiColorBulb? bulbeMode, + ShellyApiColorBulb? bulbMode, }) : super( deviceVendor: DeviceVendor(VendorsAndServices.shelly.toString()), ) { - shellyColorBulb = bulbeMode ?? + shellyColorBulb = bulbMode ?? ShellyApiColorBulb( lastKnownIp: deviceLastKnownIp.getOrCrash(), mDnsName: deviceMdns.getOrCrash(), diff --git a/lib/infrastructure/devices/shelly/shelly_relay_switch/shelly_relay_switch_entity.dart b/lib/infrastructure/devices/shelly/shelly_relay_switch/shelly_relay_switch_entity.dart index 7c60fc5c..92eb26e5 100644 --- a/lib/infrastructure/devices/shelly/shelly_relay_switch/shelly_relay_switch_entity.dart +++ b/lib/infrastructure/devices/shelly/shelly_relay_switch/shelly_relay_switch_entity.dart @@ -6,10 +6,10 @@ import 'package:cbj_hub/domain/generic_devices/abstract_device/value_objects_cor import 'package:cbj_hub/domain/generic_devices/device_type_enums.dart'; import 'package:cbj_hub/domain/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:cbj_hub/domain/generic_devices/generic_switch_device/generic_switch_value_objects.dart'; -import 'package:cbj_hub/infrastructure/devices/shelly/shelly_api/shelly_api_relay_switch.dart'; import 'package:cbj_hub/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_hub/utils.dart'; import 'package:dartz/dartz.dart'; +import 'package:shelly/shelly.dart'; class ShellyRelaySwitchEntity extends GenericSwitchDE { ShellyRelaySwitchEntity({ diff --git a/lib/infrastructure/devices/switcher/switcher_api/switcher_api_object.dart b/lib/infrastructure/devices/switcher/switcher_api/switcher_api_object.dart deleted file mode 100644 index ce1cda29..00000000 --- a/lib/infrastructure/devices/switcher/switcher_api/switcher_api_object.dart +++ /dev/null @@ -1,678 +0,0 @@ -import 'dart:convert'; -import 'dart:io'; -import 'dart:typed_data'; - -import 'package:cbj_hub/utils.dart'; -import 'package:crclib/crclib.dart'; - -class SwitcherApiObject { - SwitcherApiObject({ - required this.deviceType, - required this.deviceId, - required this.switcherIp, - required this.switcherName, - required this.powerConsumption, - required this.macAddress, - this.deviceState = SwitcherDeviceState.cantGetState, - this.deviceDirection = SwitcherDeviceDirection.cantGetState, - this.devicePass = '00000000', - this.phoneId = '0000', - this.statusSocket, - this.log, - this.port = switcherTcpPort, - this.lastShutdownRemainingSecondsValue, - this.remainingTimeForExecution, - }); - - factory SwitcherApiObject.createWithBytes(Datagram datagram) { - final Uint8List data = datagram.data; - - final List messageBuffer = intListToHex(data); - - final List hexSeparatedLetters = []; - - for (final String hexValue in messageBuffer) { - for (final element in hexValue.runes) { - hexSeparatedLetters.add(String.fromCharCode(element)); - } - } - - if (!isSwitcherMessage(data, hexSeparatedLetters) && - !isSwitcherMessageNew(data, hexSeparatedLetters)) { - logger.w('Not a switcher message arrived to here'); - } - - final SwitcherDevicesTypes sDeviceType = getDeviceType(messageBuffer); - final String deviceId = extractDeviceId(hexSeparatedLetters); - // final String switcherIp = extractIpAddr(hexSeparatedLetters); - final String switcherIp = datagram.address.address; - final String switcherMac = extractMac(hexSeparatedLetters); - final String powerConsumption = - extractPowerConsumption(hexSeparatedLetters); - - final String switcherName = extractDeviceName(data); - - final String getRemaining = - extractRemainingTimeForExecution(hexSeparatedLetters); - final String lastShutdownRemainingSecondsValue = - extractShutdownRemainingSeconds(hexSeparatedLetters); - - if (sDeviceType == SwitcherDevicesTypes.switcherRunner || - sDeviceType == SwitcherDevicesTypes.switcherRunnerMini) { - if (!isSwitcherMessageNew(data, hexSeparatedLetters)) { - logger.v('Not new switcher device!'); - } - - final SwitcherDeviceDirection switcherDeviceDirection = - extractSwitchDirection(hexSeparatedLetters); - - return SwitcherApiObject( - deviceType: sDeviceType, - deviceId: deviceId, - switcherIp: switcherIp, - deviceDirection: switcherDeviceDirection, - switcherName: switcherName, - macAddress: switcherMac, - powerConsumption: powerConsumption, - port: switcherTcpPort2, - ); - } - - if (!isSwitcherMessage(data, hexSeparatedLetters)) { - logger.v('Not old switcher device!'); - } - - final SwitcherDeviceState switcherDeviceState = - extractSwitchState(hexSeparatedLetters); - - return SwitcherApiObject( - deviceType: sDeviceType, - deviceId: deviceId, - switcherIp: switcherIp, - deviceState: switcherDeviceState, - switcherName: switcherName, - macAddress: switcherMac, - lastShutdownRemainingSecondsValue: lastShutdownRemainingSecondsValue, - powerConsumption: powerConsumption, - remainingTimeForExecution: getRemaining, - ); - } - - String deviceId; - String switcherIp; - SwitcherDevicesTypes deviceType; - SwitcherDeviceState deviceState; - SwitcherDeviceDirection deviceDirection; - int port; - String switcherName; - String phoneId; - String powerConsumption; - String devicePass; - String macAddress; - String? remainingTimeForExecution; - String? log; - String? statusSocket; - String? lastShutdownRemainingSecondsValue; - - Socket? _socket; - - String? pSession; - - static const switcherTcpPort = 9957; - static const switcherTcpPort2 = 10000; - - static const pSessionValue = '00000000'; - static const pKey = '00000000000000000000000000000000'; - - static const statusEvent = 'status'; - static const readyEvent = 'ready'; - static const errorEvent = 'error'; - static const stateChangedEvent = 'state'; - - static const switcherUdpIp = '0.0.0.0'; - static const switcherUdpPort = 20002; - - static const offValue = '0'; - static const onValue = '1'; - - static bool isSwitcherMessage( - Uint8List data, - List hexSeparatedLetters, - ) { - // Verify the broadcast message had originated from a switcher device. - return hexSeparatedLetters.sublist(0, 4).join() == 'fef0' && - data.length == 165; - } - - static bool isSwitcherMessageNew( - Uint8List data, - List hexSeparatedLetters, - ) { - // Verify the broadcast message had originated from a switcher device. - return hexSeparatedLetters.sublist(0, 4).join() == 'fef0' && - data.length == 159; - } - - static SwitcherDevicesTypes getDeviceType(List messageBuffer) { - SwitcherDevicesTypes sDevicesTypes = SwitcherDevicesTypes.notRecognized; - - final String hexModel = messageBuffer.sublist(75, 76)[0]; - - if (hexModel == '0f') { - sDevicesTypes = SwitcherDevicesTypes.switcherMini; - } else if (hexModel == 'a8') { - sDevicesTypes = SwitcherDevicesTypes.switcherPowerPlug; - } else if (hexModel == '0b') { - sDevicesTypes = SwitcherDevicesTypes.switcherTouch; - } else if (hexModel == 'a7') { - sDevicesTypes = SwitcherDevicesTypes.switcherV2Esp; - } else if (hexModel == 'a1') { - sDevicesTypes = SwitcherDevicesTypes.switcherV2qualcomm; - } else if (hexModel == '17') { - sDevicesTypes = SwitcherDevicesTypes.switcherV4; - } else if (hexModel == '01') { - sDevicesTypes = SwitcherDevicesTypes.switcherRunner; - } else if (hexModel == '02') { - sDevicesTypes = SwitcherDevicesTypes.switcherRunnerMini; - } else { - logger.w('New device type? hexModel:$hexModel'); - } - - return sDevicesTypes; - } - - Future turnOn({int duration = 0}) async { - final String offCommand = '${onValue}00${_timerValue(duration)}'; - - await _runPowerCommand(offCommand); - } - - Future turnOff() async { - const String offCommand = '${offValue}0000000000'; - await _runPowerCommand(offCommand); - } - - Future _runPowerCommand(String commandType) async { - pSession = await _login(); - if (pSession == 'B') { - logger.e('Switcher run power command error'); - return; - } - var data = - 'fef05d0002320102${pSession!}340001000000000000000000${_getTimeStamp()}' - '00000000000000000000f0fe${deviceId}00${phoneId}0000$devicePass' - '000000000000000000000000000000000000000000000000000000000106000' - '$commandType'; - - data = await _crcSignFullPacketComKey(data, pKey); - - _socket = await getSocket(); - _socket!.add(hexStringToDecimalList(data)); - await _socket?.close(); - _socket = null; - } - - /// Stops the blinds - Future stopBlinds() async { - if (deviceType != SwitcherDevicesTypes.switcherRunner && - deviceType != SwitcherDevicesTypes.switcherRunnerMini) { - logger.v('Stop blinds support only for blinds'); - return; - } - - pSession = await _login2(); - if (pSession == 'B') { - logger.e('Switcher run position command error'); - return; - } - var data = - 'fef0590003050102${pSession!}232301000000000000000000${_getTimeStamp()}' - '00000000000000000000f0fe${deviceId}00${phoneId}0000$devicePass' - '000000000000000000000000000000000000000000000000000000370202000000'; - - data = await _crcSignFullPacketComKey(data, pKey); - - _socket = await getSocket(); - _socket!.add(hexStringToDecimalList(data)); - await _socket?.close(); - _socket = null; - } - - /// Sets the position of the blinds, 0 is down 100 is up - Future setPosition({int pos = 0}) async { - if (deviceType != SwitcherDevicesTypes.switcherRunner && - deviceType != SwitcherDevicesTypes.switcherRunnerMini) { - logger.v('Set position support only blinds'); - return; - } - - final String positionCommand = _getHexPos(pos: pos); - _runPositionCommand(positionCommand); - } - - String _getHexPos({int pos = 0}) { - String posAsHex = intListToHex([pos]).join(); - if (posAsHex.length < 2) { - posAsHex = '0$posAsHex'; - } - return posAsHex; - } - - Future _runPositionCommand(String positionCommand) async { - // final int pos = int.parse(positionCommand, radix: 16); - pSession = await _login2(); - if (pSession == 'B') { - logger.e('Switcher run position command error'); - return; - } - var data = - 'fef0580003050102${pSession!}290401000000000000000000${_getTimeStamp()}' - '00000000000000000000f0fe${deviceId}00${phoneId}0000$devicePass' - '00000000000000000000000000000000000000000000000000000037010100' - '$positionCommand'; - - data = await _crcSignFullPacketComKey(data, pKey); - - _socket = await getSocket(); - _socket!.add(hexStringToDecimalList(data)); - await _socket?.close(); - _socket = null; - } - - /// Used for sending actions to the device - void sendState({required SwitcherDeviceState command, int minutes = 0}) { - _getFullState(); - } - - /// Used for sending the get state packet to the device. - /// Returns a tuple of hex timestamp, - /// session id and an instance of SwitcherStateResponse - Future _getFullState() async { - return _login(); - } - - /// Used for sending the login packet to the device. - Future _login() async { - try { - String data = 'fef052000232a100${pSessionValue}340001000000000000000000' - '${_getTimeStamp()}00000000000000000000f0fe1c00${phoneId}0000' - '$devicePass' - '00000000000000000000000000000000000000000000000000000000'; - - data = await _crcSignFullPacketComKey(data, pKey); - _socket = await getSocket(); - if (_socket == null) { - throw 'Error'; - } - - _socket!.add(hexStringToDecimalList(data)); - - final Uint8List firstData = await _socket!.first; - final String resultSession = - substrLikeInJavaScript(intListToHex(firstData).join(), 16, 8); - - return resultSession; - } catch (error) { - logger.e('Switcher login failed due to an error\n$error'); - pSession = 'B'; - } - return pSession!; - } - - /// Used for sending the login packet to switcher runner. - Future _login2() async { - // if (pSession != null) return pSession!; - - try { - String data = 'fef030000305a600${pSessionValue}ff0301000000$phoneId' - '00000000${_getTimeStamp()}00000000000000000000f0fe${deviceId}00'; - - data = await _crcSignFullPacketComKey(data, pKey); - _socket = await getSocket(); - if (_socket == null) { - throw 'Error'; - } - - _socket!.add(hexStringToDecimalList(data)); - - final Uint8List firstData = await _socket!.first; - - final String resultSession = - substrLikeInJavaScript(intListToHex(firstData).join(), 16, 8); - - return resultSession; - } catch (error) { - logger.e('login2 failed due to an error\n$error'); - pSession = 'B'; - } - return pSession!; - } - - static Future _crcSignFullPacketComKey( - String pData, - String pKey, - ) async { - String pDataTemp = pData; - final List bufferHex = hexStringToDecimalList(pDataTemp); - - String crc = intListToHex( - packBigEndian( - int.parse(Crc16XmodemWith0x1021().convert(bufferHex).toString()), - ), - ).join(); - - pDataTemp = pDataTemp + - substrLikeInJavaScript(crc, 6, 2) + - substrLikeInJavaScript(crc, 4, 2); - - crc = substrLikeInJavaScript(crc, 6, 2) + - substrLikeInJavaScript(crc, 4, 2) + - getUtf8Encoded(pKey); - - crc = intListToHex( - packBigEndian( - int.parse( - Crc16XmodemWith0x1021() - .convert(hexStringToDecimalList(crc)) - .toString(), - ), - ), - ).join(); - - return pDataTemp + - substrLikeInJavaScript(crc, 6, 2) + - substrLikeInJavaScript(crc, 4, 2); - } - - static String _getTimeStamp() { - final int timeInSeconds = DateTime.now().millisecondsSinceEpoch ~/ 1000; - - final List timeInBytes = packLittleEndian(timeInSeconds); - - return intListToHex(timeInBytes).join(); - } - - /// Same as Buffer.from(value, 'hex') in JavaScript - static List hexStringToDecimalList(String hex) { - final List decimalIntList = []; - String twoNumbers = ''; - - for (int i = 0; i < hex.length; i++) { - if (twoNumbers == '') { - twoNumbers = twoNumbers + hex[i]; - continue; - } else { - twoNumbers = twoNumbers + hex[i]; - decimalIntList.add(int.parse(twoNumbers, radix: 16)); - twoNumbers = ''; - } - } - return decimalIntList; - } - - /// Convert number to unsigned integer as little-endian sequence of bytes - /// Same as struct.pack(' packLittleEndian(int valueToConvert) { - final ByteData sendValueBytes = ByteData(8); - - try { - sendValueBytes.setUint64(0, valueToConvert, Endian.little); - } on Exception { - sendValueBytes.setUint32(0, valueToConvert, Endian.little); - } - - final Uint8List timeInBytes = sendValueBytes.buffer.asUint8List(); - return timeInBytes.sublist(0, timeInBytes.length - 4); - } - - /// Convert number to unsigned integer as big-endian sequence of bytes - /// Same as struct.pack('>I', value) in JavaScript - static List packBigEndian(int valueToConvert) { - final ByteData sendValueBytes = ByteData(8); - - try { - sendValueBytes.setUint64(0, valueToConvert); - } on Exception { - sendValueBytes.setUint32(0, valueToConvert); - } - - final Uint8List timeInBytes = sendValueBytes.buffer.asUint8List(); - return timeInBytes.sublist(4); - } - - /// Convert list of bytes/integers into their hex 16 value with padding 2 of 0 - /// Same as .toString('hex'); in JavaScript - static List intListToHex(List bytes) { - final List messageBuffer = []; - - for (final int unit8 in bytes) { - messageBuffer.add(unit8.toRadixString(16).padLeft(2, '0')); - } - return messageBuffer; - } - - /// Generate hexadecimal representation of the current timestamp. - /// Return: Hexadecimal representation of the current - /// unix time retrieved by ``time.time``. - String currentTimestampToHexadecimal() { - final String currentTimeSinceEpoch = - DateTime.now().millisecondsSinceEpoch.toString(); - final String currentTimeRounded = - currentTimeSinceEpoch.substring(0, currentTimeSinceEpoch.length - 3); - - final int currentTimeInt = int.parse(currentTimeRounded); - - return currentTimeInt.toRadixString(16).padLeft(2, '0'); - } - - /// Extract the IP address from the broadcast message. - static String extractIpAddr(List hexSeparatedLetters) { - final String ipAddrSection = - substrLikeInJavaScript(hexSeparatedLetters.join(), 152, 8); - - final int ipAddrInt = int.parse( - substrLikeInJavaScript(ipAddrSection, 0, 2) + - substrLikeInJavaScript(ipAddrSection, 2, 2) + - substrLikeInJavaScript(ipAddrSection, 4, 2) + - substrLikeInJavaScript(ipAddrSection, 6, 2), - radix: 16, - ); - return ipAddrInt.toString(); - } - - static String extractPowerConsumption(List hexSeparatedLetters) { - // final List hexPowerConsumption = - // hexSeparatedLetters.sublist(270, 278); - // TODO: fix this method does not return number, hexPowerConsumption.join() - // return the value 64000000 - // return hexPowerConsumption.join(); - return '0'; - } - - /// Extract the time remains for the current execution. - static String extractRemainingTimeForExecution( - List hexSeparatedLetters, - ) { - final List hexPowerConsumption = - hexSeparatedLetters.sublist(294, 302); - try { - final int sum = int.parse(hexPowerConsumption.sublist(6, 8).join()) + - int.parse(hexPowerConsumption.sublist(4, 6).join()) + - int.parse(hexPowerConsumption.sublist(2, 4).join()) + - int.parse(hexPowerConsumption.sublist(0, 2).join()); - return sum.toString(); - } catch (e) { - return hexPowerConsumption.join(); - } - } - - /// Substring like in JavaScript - /// If first index is bigger than second index than it will cut until the - /// first and will get the second index number of characters from there - static String substrLikeInJavaScript( - String text, - int firstIndex, - int secondIndex, - ) { - String tempText = text; - if (firstIndex > secondIndex) { - tempText = tempText.substring(firstIndex); - tempText = tempText.substring(0, secondIndex); - } else { - tempText = tempText.substring(firstIndex, secondIndex); - } - return tempText; - } - - static String extractMac(List hexSeparatedLetters) { - final String macNoColon = - hexSeparatedLetters.sublist(160, 172).join().toUpperCase(); - final String macAddress = '${macNoColon.substring(0, 2)}:' - '${macNoColon.substring(2, 4)}:${macNoColon.substring(4, 6)}:' - '${macNoColon.substring(6, 8)}:${macNoColon.substring(8, 10)}:' - '${macNoColon.substring(10, 12)}'; - - return macAddress; - } - - static String extractDeviceName(List data) { - return utf8.decode(data.sublist(42, 74)).replaceAll('\u0000', ''); - // Maybe better name handling will be - // this.data_str.substr(38, 32).replace(/[^0-9a-zA-Z_\s]/g, '').replace(/\0/g, '') - } - - /// Same as Buffer.from(value) in javascript - /// Not to be confused with Buffer.from(value, 'hex') - static String getUtf8Encoded(String list) { - final List encoded = utf8.encode(list); - - return intListToHex(encoded).join(); - } - - static String extractShutdownRemainingSeconds( - List hexSeparatedLetters, - ) { - // final String hexAutoShutdownVal = - // hexSeparatedLetters.sublist(310, 318).join(); - final String timeLeftSeconds = - substrLikeInJavaScript(hexSeparatedLetters.join(), 294, 8); - - return int.parse( - substrLikeInJavaScript(timeLeftSeconds, 6, 8) + - substrLikeInJavaScript(timeLeftSeconds, 4, 6) + - substrLikeInJavaScript(timeLeftSeconds, 2, 4) + - substrLikeInJavaScript(timeLeftSeconds, 0, 2), - radix: 16, - ).toString(); - } - - static String extractDeviceId(List hexSeparatedLetters) { - return hexSeparatedLetters.sublist(36, 42).join(); - } - - static SwitcherDeviceState extractSwitchState( - List hexSeparatedLetters, - ) { - SwitcherDeviceState switcherDeviceState = SwitcherDeviceState.cantGetState; - - final String hexModel = - substrLikeInJavaScript(hexSeparatedLetters.join(), 266, 4); - - if (hexModel == '0100') { - switcherDeviceState = SwitcherDeviceState.on; - } else if (hexModel == '0000') { - switcherDeviceState = SwitcherDeviceState.off; - } else { - logger.w('Switcher state is not recognized: $hexModel'); - } - return switcherDeviceState; - } - - static SwitcherDeviceDirection extractSwitchDirection( - List hexSeparatedLetters, - ) { - SwitcherDeviceDirection switcherDeviceState = - SwitcherDeviceDirection.cantGetState; - - final String hexModel = - substrLikeInJavaScript(hexSeparatedLetters.join(), 274, 4); - - if (hexModel == '0000') { - switcherDeviceState = SwitcherDeviceDirection.stop; - } else if (hexModel == '0100') { - switcherDeviceState = SwitcherDeviceDirection.up; - } else if (hexModel == '0001') { - switcherDeviceState = SwitcherDeviceDirection.down; - } else { - logger.w('Switcher direction is not recognized: $hexModel'); - } - return switcherDeviceState; - } - - Future getSocket() async { - if (_socket != null) { - return _socket!; - } - - try { - final Socket socket = await _connect(switcherIp, port); - return socket; - } catch (e) { - _socket = null; - logger.e('Error connecting to socket for switcher device: $e'); - rethrow; - } - } - - Future _connect(String ip, int port) async { - return Socket.connect(ip, port); - } - - String _timerValue(int minutes) { - if (minutes == 0) { - // when duration set to zero, Switcher sends regular on command - return '00000000'; - } - final seconds = minutes * 60; - return intListToHex(packLittleEndian(seconds)).join(); - } -} - -class Crc16XmodemWith0x1021 extends ParametricCrc { - Crc16XmodemWith0x1021() - : super( - 16, - 0x1021, - 0x1021, - 0x0000, - inputReflected: false, - outputReflected: false, - ); -} - -enum SwitcherDeviceDirection { - cantGetState, - stop, // '0000' - up, // '0100' - down, // '0001' -} - -/// Enum class representing the device's state. -enum SwitcherDeviceState { - cantGetState, - on, // '0100' - off, // '0000' -} - -/// Enum for relaying the type of the switcher devices. -enum SwitcherDevicesTypes { - notRecognized, - switcherMini, // MINI = "Switcher Mini", "0f", DeviceCategory.WATER_HEATER - switcherPowerPlug, // POWER_PLUG = "Switcher Power Plug", "a8", DeviceCategory.POWER_PLUG - switcherTouch, // TOUCH = "Switcher Touch", "0b", DeviceCategory.WATER_HEATER - switcherV2Esp, // V2_ESP = "Switcher V2 (esp)", "a7", DeviceCategory.WATER_HEATER - switcherV2qualcomm, // V2_QCA = "Switcher V2 (qualcomm)", "a1", DeviceCategory.WATER_HEATER - switcherV4, // V4 = "Switcher V4", "17", DeviceCategory.WATER_HEATER - switcherRunner, // runner = "Switcher Runner", "01", DeviceCategory.Blinds - switcherRunnerMini, // runner_mini = "Switcher Runner Mini", "02", DeviceCategory.Blinds -} diff --git a/lib/infrastructure/devices/switcher/switcher_api/switcher_discover.dart b/lib/infrastructure/devices/switcher/switcher_api/switcher_discover.dart deleted file mode 100644 index 3ca4179e..00000000 --- a/lib/infrastructure/devices/switcher/switcher_api/switcher_discover.dart +++ /dev/null @@ -1,50 +0,0 @@ -import 'dart:io'; - -import 'package:cbj_hub/infrastructure/devices/switcher/switcher_api/switcher_api_object.dart'; -import 'package:cbj_hub/utils.dart'; - -class SwitcherDiscover { - static const switcherUdpPort = 20002; - static const switcherUdpPort2 = 20003; - - static Stream discover20002Devices() async* { - try { - final RawDatagramSocket socket20002 = await RawDatagramSocket.bind( - InternetAddress.anyIPv4, - switcherUdpPort, - ); - - await for (final event in socket20002) { - final Datagram? datagram = socket20002.receive(); - if (datagram == null) continue; - final SwitcherApiObject switcherApiObject = - SwitcherApiObject.createWithBytes(datagram); - - yield switcherApiObject; - } - } catch (e) { - logger.e('Switcher discover devices got and exception: $e'); - } - } - - /// Blinds 20003 includes blinds for example - static Stream discover20003Devices() async* { - try { - final RawDatagramSocket socket20003 = await RawDatagramSocket.bind( - InternetAddress.anyIPv4, - switcherUdpPort2, - ); - - await for (final event in socket20003) { - final Datagram? datagram = socket20003.receive(); - if (datagram == null) continue; - final SwitcherApiObject switcherApiObject = - SwitcherApiObject.createWithBytes(datagram); - - yield switcherApiObject; - } - } catch (e) { - logger.e('Switcher discover devices got and exception: $e'); - } - } -} diff --git a/lib/infrastructure/devices/switcher/switcher_api/switcher_packets.dart b/lib/infrastructure/devices/switcher/switcher_api/switcher_packets.dart deleted file mode 100644 index 8be0fe98..00000000 --- a/lib/infrastructure/devices/switcher/switcher_api/switcher_packets.dart +++ /dev/null @@ -1,51 +0,0 @@ -class SwitcherPackets { - ///Switcher integration TCP socket API packet formats./// - - /// weekdays sum, start-time timestamp, end-time timestamp - static const scheduleCreateDataFormat = '01{}01{}{}'; - - static const noTimerRequested = '00000000'; - - static const nonRecurringSchedule = '00'; - - /// format values are local session id, timestamp - static const requestFormat = - '{}340001000000000000000000{}00000000000000000000f0fe'; - - static const pad74Zeros = - '000000000000000000000000000000000000000000000000000000000000000000000' - '0000'; - - /// format value just timestamp (initial session id is '00000000') - static String loginPacket = - 'fef052000232a10000000000${requestFormat.substring(2)}1c$pad74Zeros'; - - /// format values are local session id, timestamp, device id - static const getStatePacket = 'fef0300002320103$requestFormat{}00'; - - /// format values are local session id, timestamp, device id, command, timer - static const sendControlPacket = - 'fef05d0002320102$requestFormat{}${pad74Zeros}0106000{}00{}'; - - /// format values are local session id, timestamp, device id, auto-off seconds - static const setAutoOffSetPacket = - 'fef05b0002320102$requestFormat{}${pad74Zeros}040400{}'; - - /// format values are local session id, timestamp, device id, name - static const updateDeviceNamePacket = - 'fef0740002320202$requestFormat{}$pad74Zeros{}'; - - /// format values are local session id, timestamp, device id - static const getSchedulesPacket = - 'fef0570002320102$requestFormat{}${pad74Zeros}060000'; - - /// format values are local session id, timestamp, device id, schedule id - static const deleteSchedulePacket = - 'fef0580002320102$requestFormat{}${pad74Zeros}0801000{}'; - - /// format values are local session id, timestamp, device id, -// schedule data = -// (on_off + week + timstate + start_time + end_time) - static const createSchedulePacket = - 'fef0630002320102$requestFormat{}${pad74Zeros}030c00ff{}'; -} diff --git a/lib/infrastructure/devices/switcher/switcher_connector_conjector.dart b/lib/infrastructure/devices/switcher/switcher_connector_conjector.dart index 6ae30e63..6473f988 100644 --- a/lib/infrastructure/devices/switcher/switcher_connector_conjector.dart +++ b/lib/infrastructure/devices/switcher/switcher_connector_conjector.dart @@ -6,7 +6,6 @@ import 'package:cbj_hub/domain/generic_devices/generic_blinds_device/generic_bli import 'package:cbj_hub/domain/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; import 'package:cbj_hub/domain/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; import 'package:cbj_hub/infrastructure/devices/companies_connector_conjector.dart'; -import 'package:cbj_hub/infrastructure/devices/switcher/switcher_api/switcher_api_object.dart'; import 'package:cbj_hub/infrastructure/devices/switcher/switcher_helpers.dart'; import 'package:cbj_hub/infrastructure/devices/switcher/switcher_runner/switcher_runner_entity.dart'; import 'package:cbj_hub/infrastructure/devices/switcher/switcher_smart_plug/switcher_smart_plug_entity.dart'; @@ -14,6 +13,7 @@ import 'package:cbj_hub/infrastructure/devices/switcher/switcher_v2/switcher_v2_ import 'package:cbj_hub/infrastructure/generic_devices/abstract_device/abstract_company_connector_conjector.dart'; import 'package:cbj_hub/utils.dart'; import 'package:injectable/injectable.dart'; +import 'package:switcher_dart/switcher_dart.dart'; @singleton class SwitcherConnectorConjector implements AbstractCompanyConnectorConjector { diff --git a/lib/infrastructure/devices/switcher/switcher_helpers.dart b/lib/infrastructure/devices/switcher/switcher_helpers.dart index 07ab752e..e2804ccc 100644 --- a/lib/infrastructure/devices/switcher/switcher_helpers.dart +++ b/lib/infrastructure/devices/switcher/switcher_helpers.dart @@ -3,12 +3,12 @@ import 'package:cbj_hub/domain/generic_devices/abstract_device/value_objects_cor import 'package:cbj_hub/domain/generic_devices/generic_blinds_device/generic_blinds_value_objects.dart'; import 'package:cbj_hub/domain/generic_devices/generic_boiler_device/generic_boiler_value_objects.dart'; import 'package:cbj_hub/domain/generic_devices/generic_smart_plug_device/generic_smart_plug_value_objects.dart'; -import 'package:cbj_hub/infrastructure/devices/switcher/switcher_api/switcher_api_object.dart'; import 'package:cbj_hub/infrastructure/devices/switcher/switcher_runner/switcher_runner_entity.dart'; import 'package:cbj_hub/infrastructure/devices/switcher/switcher_smart_plug/switcher_smart_plug_entity.dart'; import 'package:cbj_hub/infrastructure/devices/switcher/switcher_v2/switcher_v2_entity.dart'; import 'package:cbj_hub/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_hub/utils.dart'; +import 'package:switcher_dart/switcher_dart.dart'; class SwitcherHelpers { static DeviceEntityAbstract? addDiscoverdDevice({ diff --git a/lib/infrastructure/devices/switcher/switcher_runner/switcher_runner_entity.dart b/lib/infrastructure/devices/switcher/switcher_runner/switcher_runner_entity.dart index 6bac9364..f36aeb9d 100644 --- a/lib/infrastructure/devices/switcher/switcher_runner/switcher_runner_entity.dart +++ b/lib/infrastructure/devices/switcher/switcher_runner/switcher_runner_entity.dart @@ -7,11 +7,11 @@ import 'package:cbj_hub/domain/generic_devices/device_type_enums.dart'; import 'package:cbj_hub/domain/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; import 'package:cbj_hub/domain/generic_devices/generic_blinds_device/generic_blinds_value_objects.dart'; import 'package:cbj_hub/domain/mqtt_server/i_mqtt_server_repository.dart'; -import 'package:cbj_hub/infrastructure/devices/switcher/switcher_api/switcher_api_object.dart'; import 'package:cbj_hub/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_hub/injection.dart'; import 'package:cbj_hub/utils.dart'; import 'package:dartz/dartz.dart'; +import 'package:switcher_dart/switcher_dart.dart'; class SwitcherRunnerEntity extends GenericBlindsDE { SwitcherRunnerEntity({ diff --git a/lib/infrastructure/devices/switcher/switcher_smart_plug/switcher_smart_plug_entity.dart b/lib/infrastructure/devices/switcher/switcher_smart_plug/switcher_smart_plug_entity.dart index 96391c3b..8e584a84 100644 --- a/lib/infrastructure/devices/switcher/switcher_smart_plug/switcher_smart_plug_entity.dart +++ b/lib/infrastructure/devices/switcher/switcher_smart_plug/switcher_smart_plug_entity.dart @@ -7,11 +7,11 @@ import 'package:cbj_hub/domain/generic_devices/device_type_enums.dart'; import 'package:cbj_hub/domain/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; import 'package:cbj_hub/domain/generic_devices/generic_smart_plug_device/generic_smart_plug_value_objects.dart'; import 'package:cbj_hub/domain/mqtt_server/i_mqtt_server_repository.dart'; -import 'package:cbj_hub/infrastructure/devices/switcher/switcher_api/switcher_api_object.dart'; import 'package:cbj_hub/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_hub/injection.dart'; import 'package:cbj_hub/utils.dart'; import 'package:dartz/dartz.dart'; +import 'package:switcher_dart/switcher_dart.dart'; class SwitcherSmartPlugEntity extends GenericSmartPlugDE { SwitcherSmartPlugEntity({ diff --git a/lib/infrastructure/devices/switcher/switcher_v2/switcher_v2_entity.dart b/lib/infrastructure/devices/switcher/switcher_v2/switcher_v2_entity.dart index 1478f097..f4b73d19 100644 --- a/lib/infrastructure/devices/switcher/switcher_v2/switcher_v2_entity.dart +++ b/lib/infrastructure/devices/switcher/switcher_v2/switcher_v2_entity.dart @@ -7,11 +7,11 @@ import 'package:cbj_hub/domain/generic_devices/device_type_enums.dart'; import 'package:cbj_hub/domain/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; import 'package:cbj_hub/domain/generic_devices/generic_boiler_device/generic_boiler_value_objects.dart'; import 'package:cbj_hub/domain/mqtt_server/i_mqtt_server_repository.dart'; -import 'package:cbj_hub/infrastructure/devices/switcher/switcher_api/switcher_api_object.dart'; import 'package:cbj_hub/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_hub/injection.dart'; import 'package:cbj_hub/utils.dart'; import 'package:dartz/dartz.dart'; +import 'package:switcher_dart/switcher_dart.dart'; class SwitcherV2Entity extends GenericBoilerDE { SwitcherV2Entity({ diff --git a/pubspec.yaml b/pubspec.yaml index 70e09898..877c1232 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,6 +2,7 @@ name: cbj_hub description: Easy to use open source Hub to control your smart devices from one app. version: 1.3.0+6 homepage: https://cybearjinni.com +issue_tracker: https://github.com/osociety/network_tools/issues publish_to: none environment: @@ -16,11 +17,12 @@ dependencies: compute: ^1.0.2 # Collection of cyclic redundancy check (CRC) routines as Dart converters. crclib: ^3.0.0 - # Functional programming thingies, let you use multiple return types + # Interact directly with eWeLink API dart_ewelink_api: git: url: 'https://github.com/guyluz11/dart_ewelink_api.git' ref: 'develop' + # Functional programming thingies, let you use multiple return types dartz: ^0.10.1 # Allow returning more than one type of object equatable: ^2.0.5 @@ -36,8 +38,9 @@ dependencies: http: ^1.1.0 # Philips Hue API hue_dart: - git: - url: 'https://github.com/guyluz11/hue_dart.git' + path: ../hue_dart +# git: +# url: 'https://github.com/guyluz11/hue_dart.git' # Convenient code generator for get_it injectable: ^2.3.0 # Utility library that checks for an Active Internet connection @@ -51,19 +54,19 @@ dependencies: # Port of Kotlin's Kotlin Standard library for Dart/Flutter projects kt_dart: ^1.1.0 # Implementation of the LIFX HTTP API - lifx_http_api: - git: 'https://github.com/guyluz11/lifx_http_api.git' + lifx_http_api: ^0.0.17 # Small, easy to use and extensible logger which prints beautiful logs. logger: ^2.0.2+1 # A server and browser based MQTT client for Dart. mi_iot_token: ^1.1.0 + # Server and browser based MQTT client mqtt_client: ^10.0.0 # Service discovery over multicast DNS (mDNS), Bonjour, and Avahi. multicast_dns: ^0.3.2+4 - nodered: - path: ../nodered # Helps you discover open ports, devices on subnet and more. network_tools: ^4.0.1 + # Interact directly with NodeRED API + nodered: ^1.0.1+1 # Provides runtime support for a Dart implementation of protobufs. protobuf: ^3.1.0 # Python Environment Manager and Executor for dart and flutter @@ -73,6 +76,10 @@ dependencies: rxdart: ^0.27.7 # Simple, fast generation of RFC4122 UUIDs. uuid: ^4.1.0 + # Communicate with Shelly smart devices + shelly: ^1.0.0 + # Control Switcher smart home accessories + switcher_dart: ^1.0.0 # Dart library for controlling Yeelight products over LAN. yeedart: ^0.3.2