Hi,

I am building an API to access a home automation system named homematic. Physically, there are devices like light switches, dimmers, temperature sensors etc and a central control unit (CCU) that connects to the LAN and manages those devices. This CCU provides an XML-RPC interface for which I am writing a Java library. So I have objects that represent those physical devices. Lets look at an example (some of which is pseudo code):

Java Code:
public class Switch {
        private Boolean state;
        
        public Boolean getState() {
                return state;
        }

        public void setState(Boolean state) {
                CCU.sendUpdateToRealDevice(state)
                this.state = state;
        }
}
Later I plan to create a graphical interface to the whole thing which includes a GUI component for this Switch. Lets say the user uses the GUI component to flip the switch: the Switch object would contact the CCU to send the update and the CCU would actually flip the switch physically. Of course, this switch device can also be flipped by a real person that physically uses that device. This results in the CCU creating a callback via XML-RPC to my software. Now the handler for this callback would have to invoke Switch#setState(Boolean) which again would contact the CCU. See the problem? Instead I would want to update the state field in the Switch object and notify PropertyChangeListeners registered to the Switch object (which I didnt include in the example code).

How would you solve this?

cheers
serow