I am trying to design a basic IOT based home automation system like Alexa or Google Home. So can anyone explain what are the basic design patterns used in Alexa or Google Home to dynamically register new devices like Lights and Fans and perform operations on them.
I have implemented this using a command pattern using fixed set of devices, but need to scale this to take care of registering dynamic run time new objects without changing code like Alexa
public SmartHomeDevice getSmartHomeDevice(String deviceName) {
SmartHomeDevice smartHomeDevice = null;
if (SmartHomeDeviceCategoryConstants.DRAWING_ROOM_LIGHT.getName().equalsIgnoreCase(deviceName)) {
smartHomeDevice = new Light(deviceName);
} else if (SmartHomeDeviceCategoryConstants.LIVING_ROOM_FAN.getName().equalsIgnoreCase(deviceName)) {
smartHomeDevice = new Fan(deviceName);
} else if (SmartHomeDeviceCategoryConstants.SMART_CHARGER.getName().equalsIgnoreCase(deviceName)) {
smartHomeDevice = new ElectricalDevice(deviceName);
}
return smartHomeDevice;
}
}
Aucun commentaire:
Enregistrer un commentaire