Skip to content

Commit

Permalink
Improved class naming
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Dec 18, 2023
1 parent 31d4d68 commit 8b3e64d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import 'package:cbj_integrations_controller/domain/scene/value_objects_scene_cbj
import 'package:cbj_integrations_controller/infrastructure/core/injection.dart';
import 'package:cbj_integrations_controller/infrastructure/devices/device_helper/device_helper.dart';
import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_abstract.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_abstract.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_base.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_base.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_empty_entity/generic_empty_entity.dart';
import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart';
import 'package:grpc/grpc.dart';
Expand Down Expand Up @@ -89,7 +89,7 @@ class AppCommunicationRepository extends IAppCommunicationRepository {
ISavedDevicesRepo.instance
.getAllDevices()
.forEach((String id, deviceEntityToSend) {
final DeviceEntityDtoAbstract deviceDtoAbstract =
final DeviceEntityDtoBase deviceDtoAbstract =
DeviceHelper.convertDomainToDto(deviceEntityToSend);
HubRequestsToApp.streamRequestsToApp.sink.add(deviceDtoAbstract);
});
Expand Down Expand Up @@ -177,15 +177,15 @@ class AppCommunicationRepository extends IAppCommunicationRepository {
/// HubRequestsToApp stream
@override
Future<void> sendAllDevicesFromHubRequestsStream() async {
final Map<String, DeviceEntityAbstract> allDevices =
final Map<String, DeviceEntityBase> allDevices =
ISavedDevicesRepo.instance.getAllDevices();

final Map<String, RoomEntity> allRooms =
ISavedRoomsRepo.instance.getAllRooms();

if (allRooms.isEmpty) {
logger.w("Can't find smart devices in the local DB, sending empty");
final DeviceEntityAbstract emptyEntity = GenericUnsupportedDE.empty();
final DeviceEntityBase emptyEntity = GenericUnsupportedDE.empty();
HubRequestsToApp.streamRequestsToApp.sink
.add(emptyEntity.toInfrastructure());
return;
Expand All @@ -198,7 +198,7 @@ class AppCommunicationRepository extends IAppCommunicationRepository {
return MapEntry(id, jsonEncode(d.toInfrastructure().toJson()));
});

allDevices.map((String id, DeviceEntityAbstract d) {
allDevices.map((String id, DeviceEntityBase d) {
HubRequestsToApp.streamRequestsToApp.sink.add(d.toInfrastructure());
return MapEntry(id, DeviceHelper.convertDomainToJsonString(d));
});
Expand Down
12 changes: 6 additions & 6 deletions lib/infrastructure/cbj_web_server_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'dart:io';
import 'package:cbj_hub/domain/i_cbj_web_server_repository.dart';
import 'package:cbj_hub/utils.dart';
import 'package:cbj_integrations_controller/domain/i_saved_devices_repo.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_abstract.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_abstract.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_base.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_base.dart';

/// A cbj web server to interact with get current state requests from mqtt as
/// well as website to change devices state locally on the network without
Expand All @@ -29,20 +29,20 @@ class CbjWebServerRepository extends ICbjWebServerRepository {
final ISavedDevicesRepo savedDevicesRepo =
ISavedDevicesRepo.instance;

final Map<String, DeviceEntityAbstract> allDevices =
final Map<String, DeviceEntityBase> allDevices =
savedDevicesRepo.getAllDevices();

DeviceEntityAbstract? deviceObjectOfDeviceId;
DeviceEntityBase? deviceObjectOfDeviceId;

for (final DeviceEntityAbstract d in allDevices.values) {
for (final DeviceEntityBase d in allDevices.values) {
if (d.getDeviceId() == deviceId) {
deviceObjectOfDeviceId = d;
break;
}
}
if (deviceObjectOfDeviceId != null) {
final String requestedDeviceProperty = pathArgs[2];
final DeviceEntityDtoAbstract deviceEntityDtoAbstract =
final DeviceEntityDtoBase deviceEntityDtoAbstract =
deviceObjectOfDeviceId.toInfrastructure();
final Map<String, dynamic> deviceEntityJson =
deviceEntityDtoAbstract.toJson();
Expand Down
40 changes: 20 additions & 20 deletions lib/infrastructure/mqtt_server_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:cbj_hub/utils.dart';
import 'package:cbj_integrations_controller/domain/connector.dart';
import 'package:cbj_integrations_controller/domain/i_mqtt_server_repository.dart';
import 'package:cbj_integrations_controller/domain/i_saved_devices_repo.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_abstract.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_abstract.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_base.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_base.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/value_objects_core.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_blinds_entity/generic_blinds_entity.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_boiler_entity/generic_boiler_entity.dart';
Expand Down Expand Up @@ -221,10 +221,10 @@ class MqttServerRepository extends IMqttServerRepository {

final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance;

final Map<String, DeviceEntityAbstract> allDevices =
final Map<String, DeviceEntityBase> allDevices =
savedDevicesRepo.getAllDevices();

for (final DeviceEntityAbstract d in allDevices.values) {
for (final DeviceEntityBase d in allDevices.values) {
if (d.getDeviceId() == deviceId) {
final Map<String, dynamic> deviceAsJson =
d.toInfrastructure().toJson();
Expand All @@ -251,8 +251,8 @@ class MqttServerRepository extends IMqttServerRepository {
} else {
deviceAsJson[property] = propertyValueString;
}
final DeviceEntityDtoAbstract savedDeviceWithSameIdAsMqtt =
DeviceEntityDtoAbstract.fromJson(deviceAsJson);
final DeviceEntityDtoBase savedDeviceWithSameIdAsMqtt =
DeviceEntityDtoBase.fromJson(deviceAsJson);

HubRequestsToApp.streamRequestsToApp.sink
.add(savedDeviceWithSameIdAsMqtt);
Expand All @@ -275,8 +275,8 @@ class MqttServerRepository extends IMqttServerRepository {
}

@override
Future<void> publishDeviceEntity(DeviceEntityAbstract deviceEntity) async {
final DeviceEntityDtoAbstract deviceAsDto = deviceEntity.toInfrastructure();
Future<void> publishDeviceEntity(DeviceEntityBase deviceEntity) async {
final DeviceEntityDtoBase deviceAsDto = deviceEntity.toInfrastructure();

final Map<String, String> devicePropertiesAsMqttTopicsAndValues =
deviceEntityPropertiesToListOfTopicAndValue(deviceAsDto);
Expand Down Expand Up @@ -341,7 +341,7 @@ class MqttServerRepository extends IMqttServerRepository {

/// Convert device entity properties to mqtt topic and massage
Map<String, String> deviceEntityPropertiesToListOfTopicAndValue(
DeviceEntityDtoAbstract deviceEntity,
DeviceEntityDtoBase deviceEntity,
) {
final Map<String, dynamic> json = deviceEntity.toJson();
final String deviceId = json['id'].toString();
Expand All @@ -364,7 +364,7 @@ class MqttServerRepository extends IMqttServerRepository {
}

/// Get saved device dto from mqtt by device id
Future<DeviceEntityDtoAbstract> getDeviceDtoFromMqtt(
Future<DeviceEntityDtoBase> getDeviceDtoFromMqtt(
String deviceId, {
String? deviceComponentKey,
}) async {
Expand All @@ -376,19 +376,19 @@ class MqttServerRepository extends IMqttServerRepository {
final List<ChangeRecord>? a =
await readingFromMqttOnce('$pathToDeviceTopic/type');
logger.t('This is a $a');
return DeviceEntityDtoAbstract();
return DeviceEntityDtoBase();
}

/// Resend the device object throw mqtt
Future<void> findDeviceAndResendItToMqtt(String deviceId) async {
final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance;

final Map<String, DeviceEntityAbstract> allDevices =
final Map<String, DeviceEntityBase> allDevices =
savedDevicesRepo.getAllDevices();

DeviceEntityAbstract? deviceObjectOfDeviceId;
DeviceEntityBase? deviceObjectOfDeviceId;

for (final DeviceEntityAbstract d in allDevices.values) {
for (final DeviceEntityBase d in allDevices.values) {
if (d.getDeviceId() == deviceId) {
deviceObjectOfDeviceId = d;
break;
Expand All @@ -409,18 +409,18 @@ class MqttServerRepository extends IMqttServerRepository {
dynamic entityFromTheApp,
bool? gotFromApp,
}) async {
if (entityFromTheApp is DeviceEntityAbstract) {
final Map<String, DeviceEntityAbstract> allDevices =
if (entityFromTheApp is DeviceEntityBase) {
final Map<String, DeviceEntityBase> allDevices =
ISavedDevicesRepo.instance.getAllDevices();
final DeviceEntityAbstract? savedDeviceEntity =
final DeviceEntityBase? savedDeviceEntity =
allDevices[entityFromTheApp.getDeviceId()];

if (savedDeviceEntity == null) {
logger.w('Device id does not match existing device');
return;
}

MapEntry<String, DeviceEntityAbstract> deviceFromApp;
MapEntry<String, DeviceEntityBase> deviceFromApp;

if (savedDeviceEntity is GenericLightDE &&
entityFromTheApp is GenericLightDE) {
Expand Down Expand Up @@ -534,7 +534,7 @@ class MqttServerRepository extends IMqttServerRepository {

@override
Future<void> postToAppMqtt({
required DeviceEntityAbstract entityFromTheHub,
required DeviceEntityBase entityFromTheHub,
}) async {
// if (entityFromTheHub is Map<String, dynamic>) {
// if (entityFromTheHub['entityStateGRPC'] !=
Expand Down Expand Up @@ -563,7 +563,7 @@ class MqttServerRepository extends IMqttServerRepository {

@override
Future<void> postSmartDeviceToAppMqtt({
required DeviceEntityAbstract entityFromTheHub,
required DeviceEntityBase entityFromTheHub,
}) async {
postToAppMqtt(entityFromTheHub: entityFromTheHub);
}
Expand Down

0 comments on commit 8b3e64d

Please sign in to comment.