Problem with a dynamic icon in a Switch

I am trying to figure out why dynamic icons do not work with a Switch, using MQTT binding.

I want to have a switch which would have a dynamic icon displaying the status of my device (which is received via a separate MQTT channel). I believe the following code is written correctly, but it doesn’t work (the icon doesn’t change when the status received via MQTT changes):

//sitemap:
 Switch item=Clear_case mappings=[ON="Clear case"]

//items:
Switch Clear_case "" <casestatus> {mqtt="<[broker:3d_printer/clear_case/status:state:default],>[broker:3d_printer/clear_case/switch:command:ON:1]"}

I did create casestatus.png, casestatus-0.png, and casestatus-1.png inside icons folder. The MQTT incoming message is either “0” or “1”.

What is interesting that exactly the same setup (mqtt, icons) works perfectly fine when I separate my code into two items - a switch and a number:

//sitemap:
 Switch item=Clear_case mappings=[ON="Clear case"]
 Text item=Clear_case_status label="[]"

//items:
Number Clear_case_status "[%d]" <casestatus>  {mqtt="<[broker:3d_printer/clear_case/status:state:default]"}
Switch Clear_case "" <empty> {mqtt=">[broker:3d_printer/clear_case/switch:command:ON:1]"}

Which proves that I got the MQTT and dynamic icons stuff right. But I am puzzled why the same doesn’t work for the case of a dynamic icon with a single Switch item (my first example).

BTW I am using Basic UI, OpenHab2.

Can anyone tell me what I am doing wrong here?

Thanks!

Could this be related to raw vs mapped state?

I think I nailed this one. What adds to the confusion is that apparently every time I make a change related to icons (add a new icon file, or even just change the icon description in the item), I have to shut down and restart OpenHab for this to take effect. That makes it harder to converge to a proper solution.

Anyway, this now seems to work exactly as I needed, with a single sitemap element (switch) performing two functions - a button, and a state display:

\\onoff.map
0=OFF
1=ON

\\sitemap
Switch item=Clear_case mappings=[ON="Clear case"]

\\items
Switch Clear_case "" <casestatus> {mqtt=">[broker:3d_printer/clear_case/switch:command:ON:1],<[broker:3d_printer/clear_case/status:state:MAP(onoff.map)]"}

The trick was to add MAP(onoff.map), and then restart OpenHab. In my icons folder I have both casestatus-0, 1 and casestatus-on, off files, so not quite sure which one are used (probably on, off?).