as announced, here my work of last months. I hope you'll appreciate it š
The idea that guided me: clearly decoupling MySensors from Openhab. Firstly, I did this by splitting binding package in two part:
The first should be seen as a sort of "library" that does all the background and application-specific work. It must not have any dependency on smarthome API (you can see for example, MySensorsBridgeConfiguration. Now has to be mapped to MySensorsGatewayConfig. This could be sound redundant, but it is the only way to do this separation).
Second point is completely related to OpenHab. It shouldn't know anything about how MySensors works. It doesn't have the responsibility to handle application specific task like interpreting messages. All this work is now handled by MySensorsGateway, which is the high-level access point to all the function that OH may needs.
MySensorsGateway is the new actor in this binding. It replaces (encapsulating) the connection and extends features of the DeviceManager that was already present before, but never used. With gateway we could send messages, manage node/child and theirs variables (add/remove/modify) and register listeners for network events (like variable update/connection state/etc).
That is the main idea. But there are a lot of things to explain. Let me do a summary š :
Reader & Writer moved inside MySensorsAbstractConnection as private class.
Reader & Writer class for IP/Serial removed. They don't expand features of default Reader & Writer
Java 8 support added. Maven packaging works well (see pom.xml)
IrSend/IrReceive merged as a single thing with two separate channels (irSend/irReceive). (Here I ask your opinion)
DiscoveryThread removed. Now DiscoveryService does all the work
Conversion from variable state and channel state is done by MySensorsTypeConverters specified into MySensorsBindingConstant
EventRegister concept added. Responsibility to manage events is delegated to a separate class. Note about events: I preferred keep one single interface that has multiple methods. In order to make you better understand which events class are listening to, I set all methods of the interface to default. I know this is not best practice but helps š
EDIT (31/1):
MySensorsBindingConstants resized. Moved definition in the appropriate place (like MySensorsMessages for message related definition)
I hope not forgiveness. Please report me all your impressions and ideas, we could work together to accomplish the best result from this refactoring!
My TODO list:
[ ] Documenting all the new class (my next step)
[ ] expectUpdateTimeout. Put offline node that doesn't respond in a specified interval. (thinking how to do that)
Hi @tobof ,
as announced, here my work of last months. I hope you'll appreciate it š The idea that guided me: clearly decoupling MySensors from Openhab. Firstly, I did this by splitting binding package in two part:
Internal (org.openhab.mysensors.internal) <--MySensors
Non-Internal (org.openhab.mysensors) <-- OpenHab
The first should be seen as a sort of "library" that does all the background and application-specific work. It must not have any dependency on smarthome API (you can see for example, MySensorsBridgeConfiguration. Now has to be mapped to MySensorsGatewayConfig. This could be sound redundant, but it is the only way to do this separation).
Second point is completely related to OpenHab. It shouldn't know anything about how MySensors works. It doesn't have the responsibility to handle application specific task like interpreting messages. All this work is now handled by MySensorsGateway, which is the high-level access point to all the function that OH may needs.
MySensorsGateway is the new actor in this binding. It replaces (encapsulating) the connection and extends features of the DeviceManager that was already present before, but never used. With gateway we could send messages, manage node/child and theirs variables (add/remove/modify) and register listeners for network events (like variable update/connection state/etc).
That is the main idea. But there are a lot of things to explain. Let me do a summary š :
Reader & Writer moved inside MySensorsAbstractConnection as private class.
Reader & Writer class for IP/Serial removed. They don't expand features of default Reader & Writer
Java 8 support added. Maven packaging works well (see pom.xml)
IrSend/IrReceive merged as a single thing with two separate channels (irSend/irReceive). (Here I ask your opinion)
DiscoveryThread removed. Now DiscoveryService does all the work
Conversion from variable state and channel state is done by MySensorsTypeConverters specified into MySensorsBindingConstant
EventRegister concept added. Responsibility to manage events is delegated to a separate class. Note about events: I preferred keep one single interface that has multiple methods. In order to make you better understand which events class are listening to, I set all methods of the interface to default. I know this is not best practice but helps š
EDIT (31/1):
I hope not forgiveness. Please report me all your impressions and ideas, we could work together to accomplish the best result from this refactoring!
My TODO list:
[ ] Documenting all the new class (my next step)
[ ] expectUpdateTimeout. Put offline node that doesn't respond in a specified interval. (thinking how to do that)
[ ] updateVariable in gateway (not urgent)