roblans / ZWave4Net

ZWave4Net is a .NET library that interfaces with the Aeotec / Aeon Labs Z-Stick.
MIT License
41 stars 34 forks source link

Added WallPlug_V3 to support WallPlug with firmware v3. Added various… #28

Closed Kla3mus closed 5 years ago

Kla3mus commented 5 years ago

… extra features to the class

I hope this seems OK. This is my first try at a pull request. I hope I'm doing it right.

roblans commented 5 years ago

Hi, I decided to keep my original solution: one WallPlug that supports multiple firmware versions. To deal with the changed configuration values for the Colors I made a generic solution to cope with it:

      public enum LedRingColorOn : byte
        {
            [ConfigurationValue(0x00)]
            [ConfigurationValue(0x09, FirmwareVersion.V2)]
            Off,

            [ConfigurationValue(0x01)]
            [ConfigurationValue(0x01, FirmwareVersion.V2)]
            PowerLoadContinuously,

This approach allows you to define different configuration values for a Enum, and will no longer use the underlying value of the Enum.

I merged the new Get/SetEnergyReportingThreshold and Get/SetOverloadSafetySwitch methods from you (thanks for implementing these) and made them compatible with V2 of the firmware.

Regards,

Rob.

Kla3mus commented 5 years ago

I like it! - way more elegant :)

I have been thinking a lot about these implementations lately, and how this would/could playout in an application (which i am planning to create). I have some suggestions that i'm wondering if you would be interested in checking out.

There could be small interfaces for the different kinds of features that each hardware entity has. For the wallplug it could look something like this:

public interface ISocket
{
    void Switch(bool state);
}
public interface IPowerMeasure { /*Events*/ }
public interface ILedRing { /*Set colors*/ }

These would then be implemented on the wallplug as such:

/// <summary>
/// Protocol: Z-Wave
/// Company: Fibaro
/// Device: Wall Plub
/// Model: FGWPE/F-102 ZW5
/// </summary>
public class WallPlug : ISocket, IPowerMeasure, ILedRing
{
    public WallPlug(Node node)
    {
        node.GetCommandClass<SwitchBinary>().Changed += SwitchBinary_Changed;
    }

    public void Switch(bool state) { /* Turn on or off */ }
}

Say then that you have a zone in your house, with various plugs with different features that needs different kinds of implementation (FibaroPlug, AEON plug, maybe some zigbee or wifi plugs ++) then you could just get all devices that has ISocket and do a for loop and do a switch(true) on all of them. Or in the case of temperature sensors, you'd get all the temperature signals and make an average of them maybe. No matter what type of devices that would have the implementation, the program to use them would not care, it would just get the data of the interfaces...

It could of course be that this should be one level higher... and not in this Repo at all... i'm just suggesting :)