Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend support of dynamic icon #3461

Closed
Fejitatete opened this issue Aug 24, 2023 · 10 comments
Closed

Extend support of dynamic icon #3461

Fejitatete opened this issue Aug 24, 2023 · 10 comments
Labels
enhancement Indicates new feature requests

Comments

@Fejitatete
Copy link

Is there a possibility to extend the support of dynamic icon, like basicui.
For example : the app doesn't care about custom dynamic icon in text label (just ON / OFF, see pictures attached).

1st picture : basicui
basicui
2nd picture : android app
openhab_android

Thank you for your work & reading.
Cheers.

@Fejitatete Fejitatete added the enhancement Indicates new feature requests label Aug 24, 2023
@maniac103
Copy link
Contributor

What do you mean by 'custom dynamic icon'? Can you please show item and sitemap definition?
In general the app just includes the item state when requesting the icon, and it's up to the server to deliver the correct icon. If there's a mismatch between app and BasicUI, it must thus be inside the state sending code, and for that the item and sitemap widget definition is important.

@mueller-ma
Copy link
Member

Do you have the battery saver or data saver enabled? What's the value of loadIconsWithState in the log of the app in line ~10?

@Fejitatete
Copy link
Author

Sitemap :

Frame label="Lumières Salon" {
        Switch item=LumieresSalon
        Switch item=MiSmartLEDSalon_Power visibility=[MiSmartLEDSalon_isOnline == ON]
        Text item=MiSmartLEDSalon_isOnline visibility=[MiSmartLEDSalon_isOnline != ON]
        Text icon="settings" label="Paramètres" {
            Frame label="Allumage Sélectif" {
                Switch item=LumieresSalon_LumiereGauche
                Switch item=LumieresSalon_LumiereDroite
            }
            Frame label="Couleur & Luminosité" visibility=[MiSmartLEDSalon_isOnline == ON] {
                Switch item=MiSmartLEDSalon_Power
                Slider item=MiSmartLEDSalon_Brightness maxValue=100 minValue=1 step=1
                Colorpicker item=MiSmartLEDSalon_RGBColor
                Slider item=MiSmartLEDSalon_ColorTemperature maxValue=6500 minValue=2700 step=100
            }
            Frame label="Programmes" visibility=[MiSmartLEDSalon_isOnline == ON] {
                Selection item=MiSmartLEDSalon_ColorMode mappings=[0=Defaut,1=CT,2=RGB,3=HSV,4="Flux Lumineux",5=Veilleuse]
                Setpoint item=MiSmartLEDSalon_ShutdownTimer
            }
        }
    }

Item definition :

label: Lumière Plafond [MAP(switch.map):%s]
type: Switch
category: light
groupNames:
  - MiSmartLEDSalon
groupType: None
function: null
tags:
  - Status

Transform :

OFF=Arrêt
ON=Marche
UNDEF=Inconnu
NULL=Inconnu
-=Hors Ligne

Icon files :

|-- [openhab          750]  light--.png
|-- [openhab         1811]  light-null.png
|-- [openhab          750]  light-off.png
|-- [openhab          756]  light-on.png
|-- [openhab          756]  light.png

App debug log :

----------------------- Device information Model: Redmi K20 Pro Manufacturer: Xiaomi Brand: Xiaomi Device: raphael Product: raphael OS: 11 Display: 1080x2210, 2.75 density Data usage policy: DataUsagePolicy(canDoLargeTransfers=true, loadIconsWithState=true, autoPlayVideos=true, canDoRefreshes=true), data saver: 1, battery saver: false -----------------------

@maniac103
Copy link
Contributor

maniac103 commented Aug 29, 2023

OK, so I guess the dynamic icons for ON and OFF work fine and the issue is just with the '-' state?
(And if the answer is yes: what kind of state is this even, considering it's neither NULL nor UNDEF and Switch items can not get arbitrary string states? What binding does this state come from?)

@Fejitatete
Copy link
Author

OK, so I guess the dynamic icons for ON and OFF work fine and the issue is just with the '-' state?

Correct

What binding does this state come from?

It's a rule that postUpdate 'NULL' to the item.
AFAIK, all item with 'NULL' state are displayed '-' in basicui.

@maniac103
Copy link
Contributor

Can you show the rule? According to your transformation, NULL Updates should yield light-null.

@Fejitatete
Copy link
Author

Sorry, my mistake : the item is displayed as '-' so with the transform it become 'Hors Ligne' but the icon shown in basicui is 'light-null.png'

rule :

/* global Java, event, items, actions */ 
(function () {
  const THING_ID = 'miio:generic:0EEA652E'
  const OUTPUT_ITEM_NAME = 'MiSmartLEDSalon_isOnline'

  const thingTurnedOffline = typeof event !== 'undefined' && event.statusInfo !== undefined && event.statusInfo.status.toString() === 'OFFLINE'
  const thingTurnedOnline = typeof event !== 'undefined' && event.statusInfo !== undefined && event.statusInfo.status.toString() === 'ONLINE'

  // handle each case separately
 if (thingTurnedOffline) {
    console.debug(THING_ID + ' turned OFFLINE -> Considering non-alive (' + OUTPUT_ITEM_NAME + ')')
    items.getItem(OUTPUT_ITEM_NAME).postUpdate('NULL')
  } else if (thingTurnedOnline) {
    console.debug(THING_ID + ' turned ONLINE -> Considering alive (' + OUTPUT_ITEM_NAME + ')')
    items.getItem(OUTPUT_ITEM_NAME).postUpdate('ON')
  } else {
    //console.error('Unexpected condition')
    console.debug(THING_ID + ' turned OFFLINE -> Considering non-alive (' + OUTPUT_ITEM_NAME + ')')
    items.getItem(OUTPUT_ITEM_NAME).postUpdate('NULL')
  }
})()

@maniac103
Copy link
Contributor

Okay, so the issue is just the NULL state. I'll have a look at it.

@Fejitatete
Copy link
Author

Thank you very much.

maniac103 added a commit to maniac103/openhab.android that referenced this issue Aug 31, 2023
BasicUI set a predecent for doing so, and users are relying on that
behavior.

Fixes openhab#3461

Signed-off-by: Danny Baumann <[email protected]>
@mueller-ma
Copy link
Member

Closed by #3456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests
Projects
None yet
Development

No branches or pull requests

3 participants