HomeSeer / Plugin-SDK

Plugin development kit for the 4th major edition of the HomeSeer platform.
https://www.nuget.org/packages/HomeSeer-PluginSDK/
GNU Affero General Public License v3.0
20 stars 4 forks source link

Release v1.4.5.0 #358

Closed jldubz closed 5 months ago

jldubz commented 6 months ago

Summary

This release contains a small change to devices. The Version property was exposed on AbstractHsDevice. This property can be used to seamlessly migrate devices from a legacy configuration without having to recreate the entire device. This ensures that existing events and other links to that device remain the same. When setting the Version property to "4.0", make sure you clear all StatusControls and StatusGraphics on HsDevices first. For HsFeatures, recreate the StatusControls and StatusGraphics before setting the Version.

Changes

Example

string deviceName = (string) _hs.GetPropertyByRef(legacyDeviceRef, EProperty.Name);
//We use int instead of ERelationship here because ERelationship does not contain the Standalone=3 value
int relationship = (int)_hs.GetPropertyByRef(legacyDeviceRef, EProperty.Relationship);

switch(relationship) 
{
    case 3:
        //This is a standalone device, we need to create a root and turn the standalone device as a child of this new root
        NewDeviceData devData = DeviceFactory.CreateDevice(PLUGIN_ID)
            .WithName(deviceName)
            .PrepareForHs();

        int newDevRef = _hs.CreateDevice(devData);

        //Set the standalone ref as a child of the root
        _hs.UpdatePropertyByRef(newDevRef, EProperty.AssociatedDevices, new HashSet<int> { legacyDeviceRef });
        //Turn the standalone as a feature of the newly created device
        _hs.UpdatePropertyByRef(legacyDeviceRef, EProperty.Relationship, ERelationship.Feature);
        _hs.UpdatePropertyByRef(legacyDeviceRef, EProperty.AssociatedDevices, new HashSet<int> { newDevRef });

        //Set the interface (only needed if the new plugin has a different ID)
        _hs.UpdatePropertyByRef(legacyDeviceRef, EProperty.Interface, PLUGIN_ID);

        //Clear all the controls and status
        _hs.ClearStatusControlsByRef(legacyDeviceRef);
        _hs.ClearStatusGraphicsByRef(legacyDeviceRef);

        //Recreate them using AddStatusControlToFeature() and AddStatusGraphicToFeature()
        _hs.AddStatusControlToFeature(legacyDeviceRef, statusControl);
        ...
        _hs.AddStatusGraphicToFeature(legacyDeviceRef, statusGraphic);
        ...
        //Set the version to 4.0
        _hs.UpdatePropertyByRef(legacyDeviceRef, EProperty.Version, 4.0);
        break;
    case 2:
        //This is a root device with children and without any controls or status

        //Set the interface (only needed if the new plugin has a different ID)
        _hs.UpdatePropertyByRef(legacyDeviceRef, EProperty.Interface, PLUGIN_ID);
        ...
        //Set the version to 4.0
        _hs.UpdatePropertyByRef(legacyDeviceRef, EProperty.Version, 4.0);
        break;
    case 4:
        //This is a child device (i.e feature)

        //Set the interface (only needed if the new plugin has a different ID)
        _hs.UpdatePropertyByRef(legacyDeviceRef, EProperty.Interface, PLUGIN_ID);

        //Clear all the controls and status
        _hs.ClearStatusControlsByRef(legacyDeviceRef);
        _hs.ClearStatusGraphicsByRef(legacyDeviceRef);

        //Recreate them using AddStatusControlToFeature() and AddStatusGraphicToFeature()
        _hs.AddStatusControlToFeature(legacyDeviceRef, statusControl);
        ...
        _hs.AddStatusGraphicToFeature(legacyDeviceRef, statusGraphic);
        ...
        //Set the version to 4.0
        _hs.UpdatePropertyByRef(legacyDeviceRef, EProperty.Version, 4.0);
        break;
    default:
            //Not set / unknown state
            break;
}
jldubz commented 5 months ago

Shifting to v1.5.0.0 instead. See https://github.com/HomeSeer/Plugin-SDK/pull/359