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

Working on event actions.... #28

Closed wvuyk closed 4 years ago

wvuyk commented 4 years ago

I am trying to get my actions working. Getting close, but I see a few cchallenges where I need help, cannot find what I am missing, so either it is not yet implemented or I am not using the right tools. For reference, an image of the action screen I have build so far:

image

I am using OnConfigItemUpdate to adjust the fields shown and was hoping to catch field changes here. It only gets called when the user selects a light, or a preset or uses one of the toggles. It does not get called when the user adds a value to - for example - the Bri field.

Next, I was trying the same checks for fields with IsFullyConfigured. None of the fields holds a value during this check, toggles and selectlists seem to work fine.

Then, if the plugin returns "true" on IsFullyConfigured one would expect the values to be save somehow and returned then the action is re-opened. But somehow this is not happening at all? The action is virgin again when opened?

Can someone help me out here?

wvuyk commented 4 years ago

I got some of the event action working. It appears - with a lot of try and see....- that you cannot use GroupViews here. I was using two groupviews, after removing those the values were set and they could be checked by the plugin. This also resolved the IsFullyConfigured issue, values are now saved.

Three issues remain now:

  1. If a user fills a field with a value and then after saving the action erases it, the PluginSDK will throw an error when this is saved:
HomeSeer.Jui.Views.InvalidValueForTypeException: The new value is invalid for the input type
   bij HomeSeer.Jui.Views.InputView.Update(AbstractView newViewState)
   bij HomeSeer.Jui.Views.ViewCollectionHelper.UpdateViewById(AbstractView view, List`1& viewList, Dictionary`2& viewIds)
   bij HomeSeer.Jui.Views.Page.UpdateViewById(AbstractView view)
   bij HomeSeer.PluginSdk.Events.AbstractActionType.OnEditAction(Page viewChanges)
   bij HomeSeer.PluginSdk.Events.AbstractActionType.ProcessPostData(Dictionary`2 changes)
   bij HomeSeer.PluginSdk.Events.ActionTypeCollection.OnUpdateActionConfig(Dictionary`2 postData, TrigActInfo actInfo)

This is not caused by something the plugin initiated, I think this is during internal processing of the views during the save of the action. Maybe the pluginsdk is not expecting a field to be emptied by a user?

  1. The second issue is for InputViews created with EInputType.Decimal :

New InputView(IDInputY, "Y (between 0 and 1, 4 behind decimal point)", EInputType.Decimal)

It does not matter what I try to do here, inputting 0.1 or 0,2 or 1 (or even 'abc' is accepted here.).... When this gets saved a popup comes telling the "new value is invalid for the input type" It seems this needs some attention?

  1. I have copied the error routine from NetCam-Plugin.vb and tried to use it unchanged. In this routine a labelview is used. The labelview is, although added, not shown to the users, but can be found in the ConfigPage.views. I really would like to show this line of information, same as I did in the HS3 plugin. It can be helpfull to the users here.

A copy of the routine:

  Public Sub GenerateError(msg As String)
        'this will add a label view to the top of the page canvas with an error message
        Dim lblError As LabelView = New LabelView(ErrorId, "Error", msg)
        Dim Views As New List(Of AbstractView)
        'start the new list with the error message
        If Not ConfigPage.ViewIds.Contains(ErrorId) Then Views.Add(lblError)
        'Add in the rest of the views (if there are any)
        For Each view As AbstractView In ConfigPage.Views
            If view.Id <> ErrorId Then Views.Add(view)
        Next
        'reset the views
        ConfigPage.SetViews(Views)
    End Sub
wvuyk commented 4 years ago

And one extra question, how can I add the TimeSpan to the action? I see this for actions on devices and had this for the action of my plugin as well, but there seems to be no timerview or something similar?

jldubz commented 4 years ago

There are a few different issues being discussed here; so let's break this out into the individual items and address them one at a time.

First, it looks like there is an issue with GroupViews in Event Actions/Triggers

I got some of the event action working. It appears - with a lot of try and see....- that you cannot use GroupViews here.

New issue here - https://github.com/HomeSeer/Plugin-SDK/issues/32


If a user fills a field with a value and then after saving the action erases it, the PluginSDK will throw an error when this is saved:

HomeSeer.Jui.Views.InvalidValueForTypeException: The new value is invalid for the input type
   bij HomeSeer.Jui.Views.InputView.Update(AbstractView newViewState)
   bij HomeSeer.Jui.Views.ViewCollectionHelper.UpdateViewById(AbstractView view, List`1& viewList, Dictionary`2& viewIds)
   bij HomeSeer.Jui.Views.Page.UpdateViewById(AbstractView view)
   bij HomeSeer.PluginSdk.Events.AbstractActionType.OnEditAction(Page viewChanges)
   bij HomeSeer.PluginSdk.Events.AbstractActionType.ProcessPostData(Dictionary`2 changes)
   bij HomeSeer.PluginSdk.Events.ActionTypeCollection.OnUpdateActionConfig(Dictionary`2 postData, TrigActInfo actInfo)

This is not caused by something the plugin initiated, I think this is during internal processing of the views during the save of the action. Maybe the pluginsdk is not expecting a field to be emptied by a user?

New issue here - https://github.com/HomeSeer/Plugin-SDK/issues/33


The second issue is for InputViews created with EInputType.Decimal :

New InputView(IDInputY, "Y (between 0 and 1, 4 behind decimal point)", EInputType.Decimal)

It does not matter what I try to do here, inputting 0.1 or 0,2 or 1 (or even 'abc' is accepted here.).... When this gets saved a popup comes telling the "new value is invalid for the input type" It seems this needs some attention?

New issue here - https://github.com/HomeSeer/Plugin-SDK/issues/34


I have copied the error routine from NetCam-Plugin.vb and tried to use it unchanged. In this routine a labelview is used. The labelview is, although added, not shown to the users, but can be found in the ConfigPage.views. I really would like to show this line of information, same as I did in the HS3 plugin. It can be helpfull to the users here.

A copy of the routine:

  Public Sub GenerateError(msg As String)
        'this will add a label view to the top of the page canvas with an error message
        Dim lblError As LabelView = New LabelView(ErrorId, "Error", msg)
        Dim Views As New List(Of AbstractView)
        'start the new list with the error message
        If Not ConfigPage.ViewIds.Contains(ErrorId) Then Views.Add(lblError)
        'Add in the rest of the views (if there are any)
        For Each view As AbstractView In ConfigPage.Views
            If view.Id <> ErrorId Then Views.Add(view)
        Next
        'reset the views
        ConfigPage.SetViews(Views)
    End Sub

New issue here - https://github.com/HomeSeer/Plugin-SDK/issues/35


I am going to close this issue and continue my investigation on each of the issues in turn. If I missed one, please create an issue for it, and I will follow up with you when I have time to test each one.