Re: [mh] Adding ability to send arbitrary commands to Tasmota - CASE PROBLEM solved

Giles Godart-Brown <[email protected]> Thu, 4 Feb 2021 15:35:22 +0000
Newsgroups gmane.comp.misc.misterhouse.user
Message-ID <[email protected]>
OK, I've got to the bottom of this.

It is to do with the way MisterHouse does a set command for generic_items.

I added a line to mqtt.pm to store away the actual MQTT message just 
before it sets the object viz;

<snip>
$self->{last_mqtt_message} = $msg;
$self->SUPER::set( $msg, $p_setby, $p_response ) if defined $msg;
</snip>

If I set a value to G_OFF then compare the two, the items value is 
g_off  and the last_mqtt_message is G_OFF

It appears that this is being done in generic_item in the lines;

<snip>

     # Some devices may need to see states and substates in a case sensitive
     # manner.  This flag allows them to do so.
     $state = lc($state) unless $self->{states_casesensitive};

</snip>

so I added

$myMQTTdevice->{states_casesensitive} = 1;

And voila I get it set to G_OFF

I will update the documentation accordingly.

Giles

On 04/02/2021 09:42, Giles Godart-Brown wrote:
>
> I've taken a quick look at mqtt.pm and cannot see where the lc 
> conversion is occurring (cannot find lc anywhere) could this be higher 
> up in the MQTT::Message library?
>
> Sorry but run out of time to do more today.
>
> Giles
>
> On 03/02/2021 22:42, Paul Onley wrote:
>> I was reluctant to suggest changing the existing MQTT_DEVICE code as 
>> I had no idea how many people might be using it. I agree that 
>> returning the raw JSON is the ideal option and my opinion as a user 
>> would be that adding an option to return both versions from 
>> MQTT_DEVICE  with documentation and strongly encouraging use of the 
>> raw output for compatibility would be the best way to go.
>>
>> Again I am just a user and have little knowledge of how many people 
>> might be using the MQTT_DEVICE code, you guys are the ones developing 
>> this code and have a much better idea than I of the best way to 
>> proceed going forward.
>>
>>
>> On 2/3/21 3:16 PM, Giles Godart-Brown wrote:
>>> How about we just add $self->{raw_json} to MQTT_Device to hold the 
>>> mixed case JSON and $self->{lc_json} to Tasmota_HTTP for the lc 
>>> version and document accordingly?
>>>
>>>
>>> G
>>>
>>>> On 3 Feb 2021, at 21:01, Jeff Siddall via misterhouse-users 
>>>> <[email protected]> wrote:
>>>>
>>>> I could be wrong, but I am guessing the number of people 
>>>> converting from MQTT to Tasmota_HTTP could be counted on one hand 
>>>> (and are probably already on this thread!) so it would likely be 
>>>> easier to just convert the user code to be case insensitive instead 
>>>> of adding a bunch of backward compatibility into the code base.  
>>>> Perhaps a note on the Wiki indicating that Tasmota_HTTP::Item 
>>>> presents the JSON directly from Tasmota whereas MQTT lower cases 
>>>> all the data so people are aware.
>>>>
>>>> Jeff
>>>>
>>>>> On 2021-02-03 3:39 p.m., Giles Godart-Brown wrote:
>>>>>
>>>>> I'm with Jeff on this one, MisterHouse shouldn't be messing with 
>>>>> the case of a JSON message.
>>>>>
>>>>> The only exception I've currently coded in Tasmota_HTTP::Item is 
>>>>> the edge case where someone sends a run_cmnd with no command 
>>>>> string, in which case it just returns the state of the device in 
>>>>> lower case (on or off) to be consistent with MisterHouse states.
>>>>>
>>>>> I'll take a look at MQTT_DEVICE in the morning and see where the 
>>>>> lc is creeping in, maybe we can double up the JSON to have both 
>>>>> mixed case and lower case keys and values in the response so 
>>>>> current code doesn't break?
>>>>>
>>>>> G
>>>>>
>>>>
>>>> ________________________________________________________
>>>> To unsubscribe from this list, go to: 
>>>> https://lists.sourceforge.net/lists/listinfo/misterhouse-users
>>>>
>>>
>>> ________________________________________________________
>>> To unsubscribe from this list, go to: 
>>> https://lists.sourceforge.net/lists/listinfo/misterhouse-users
>>>
>>
>>
>>
>> ________________________________________________________
>> To unsubscribe from this list, go to: 
>> https://lists.sourceforge.net/lists/listinfo/misterhouse-users
>>

________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users