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

Casting Error during Load #20

Open
LuiSauberhorn opened this issue Jan 1, 2023 · 1 comment
Open

Casting Error during Load #20

LuiSauberhorn opened this issue Jan 1, 2023 · 1 comment

Comments

@LuiSauberhorn
Copy link

The Widget works very well but causes some Scripting Errors during load (after that it works fine, seems to be an initialization problem when items are not available yet):

Error: [sprintf] expecting number but found string
@https://<Server>/habpanel/vendor/vendor.js:365:1039
b@https://<Server>/habpanel/vendor/vendor.js:365:121
@https://<Server>/habpanel/vendor/vendor.js:536:96
@https://<Server>/habpanel/vendor/vendor.js:255:82
@https://<Server>/habpanel/vendor/vendor.js:130:278
@https://<Server>/habpanel/vendor/vendor.js:128:440
$digest@https://<Server>/habpanel/vendor/vendor.js:144:321
$apply@https://<Server>/habpanel/vendor/vendor.js:147:370
@https://<Server>/habpanel/vendor/vendor.js:160:394
f@https://<Server>/habpanel/vendor/vendor.js:45:497
@https://<Server>/habpanel/vendor/vendor.js:48:419
4vendor.js:92

For me, an implicit cast with a default value worked fine for all sprint statements.

'%.1f' | sprintf:(<value>)

changed to

'%.1f' | sprintf:(+<value> || 0)

That means after replacing the nine sprint statements, the template line looks as follows now:

"template": "<!-- For more information goto: https://github.com/BasvanH/habpanel-widget-openweathermap -->\n\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/openweathermap/weather-icons-master/css/weather-icons.css\">\n\n<style>\n@media (min-width: 992px) {\n .col-md-border:not(:last-child) {\n\t\t\tborder-right: 1px solid #d7d7d7;\n }\n \t.col-left-border {\n \t\tborder-left: 1px solid #d7d7d7;\n \t\tmargin-left: -1px;\n \t\tmargin-right: 1px;\n \t}\n \t.owm-to-upper:first-letter {\n \ttext-transform: uppercase;\n\t\t}\n \t.owm-condition {\n \t\theight: 2em;\n \t\t}\n \t.owm-row-current {\n \t\tmargin: 1em 0em 2em;\n \t\t}\n .owm-row-detail-header {\n \t\tpadding-left: 5px;\n \t\tpadding-right: 5px;\n \t\tmargin-bottom: 0em;\n \t\t}\n \t.owm-row-detail-forecast {\n \t\tpadding-left: 5px;\n \t\tpadding-right: 5px;\n \t\tpadding-top: 0em;\n \t\tmargin-bottom: 1em;\n \t\t}\n \t.owm-row-forecast {\n \t\tmargin-bottom: 1em;\n \t\tmargin-top: 3em;\n \t\t}\n}\n</style>\n<div oc-lazy-load=\"['/static/openweathermap/owm.controller.js']\">\n\t<div ng-controller=\"ngOwmCtrl\">\n <div ng-if=\"config.show_current\", class=\"row owm-row-current\">\n <div class=\"col-xs-9\">\n <i class=\"wi wi-owm-{{ itemValue('Weather_OWM_ConditionId') }} pull-right\" ng-style=\"{ 'color' : (config.icon_color_current == NULL ? primary-color : config.icon_color_current), 'font-size' : (config.icon_size_current == NULL ? '10em' : config.icon_size_current + 'em') }\"></i>\n <h2 class=\"text-left owm-to-upper\">{{ itemValue('Weather_OWM_Condition') }}</h2>\n </div>\n <div class=\"col-xs-3 text-right\">\n <h2>{{ '%.1f' | sprintf:(+itemValue('Weather_OWM_Temperature').split(' ')[0] || 0)}} {{ itemValue('Weather_OWM_Temperature').split(' ')[1] }}</h2>\n <h5><img style=\"height:16px;\" src=\"/static/openweathermap/images/humidity.png\"/> {{itemValue('Weather_OWM_Humidity') }}</h5>\n <h5><img style=\"height:16px;\" src=\"/static/openweathermap/images/wind.png\"/> {{ '%.1f' | sprintf:(+itemValue('Weather_OWM_Wind_Speed').split(' ')[0] || 0)}} {{ itemValue('Weather_OWM_Wind_Speed').split(' ')[1] }}</h5>\n <h5>{{ itemValue('Weather_OWM_ObservationTime') | date: 'HH:mm' }}</h5>\n <h5 ng-if=\"config.station_name\">{{ itemValue('Weather_OWM_Station_Name') }}</h5>\n </div>\n </div>\n <div ng-if=\"config.show_detail_6h_1_5days\">\n <div ng-app=\"\" ng-init=\"hours=['6','12','18','24','30','36']\">\n <div class=\"row owm-row-detail-header\">\n <div ng-repeat=\"hour in hours\">\n <div ng-if=\"((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') > 4) && ((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') < 11)\", class=\"col-xs-2 col-left-border\">\n <h4>{{ itemValue('Weather_OWM_DateTime_h' + hour) | date: 'EEE' }}</h4>\n </div>\n <div ng-if=\"((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') < 5) || ((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') > 10)\", class=\"col-xs-2\">\n <h4>&nbsp</h4>\n </div>\n </div>\n </div>\n <div class=\"row owm-row-detail-forecast\">\n <div ng-repeat=\"hour in hours\", class=\"col-xs-2 col-md-border\">\n <h6>{{ itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH:mm' }}</h6>\n <i class=\"wi wi-owm-{{ itemValue('Weather_OWM_ConditionId_h' + hour) }}\" ng-style=\"{ 'color' : (config.icon_color_forecast == NULL ? primary-color : config.icon_color_forecast), 'font-size' : (config.icon_size_detail == NULL ? '1em' : config.icon_size_detail + 'em') }\"></i>\n <h5>{{ '%.0f' | sprintf:(+itemValue('Weather_OWM_Temp_h' + hour).split(' ')[0] || 0)}}{{ itemValue('Weather_OWM_Temp_h' + hour).split(' ')[1] }}</h5>\n </div>\n </div>\n </div>\n </div>\n <div ng-if=\"config.show_detail_3h_1_5days\" class=\"row owm-row-detail-forecast\">\n <div ng-app=\"\" ng-init=\"hours=['3','6','9','12','15','18','21','24','27','30','33','36']\">\n <div class=\"row owm-row-detail-header\">\n <div ng-repeat=\"hour in hours\">\n <div ng-if=\"((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') > 3) && ((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') < 7)\", class=\"col-xs-1 col-left-border\">\n <h4>{{ itemValue('Weather_OWM_DateTime_h' + hour) | date: 'EEE' }}</h4>\n </div>\n <div ng-if=\"((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') < 4) || ((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') > 6)\", class=\"col-xs-1\">\n <h4>&nbsp</h4>\n </div>\n </div>\n </div>\n <div class=\"row owm-row-detail-forecast\">\n <div ng-repeat=\"hour in hours\", class=\"col-xs-1 col-md-border\">\n <h6>{{ itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH:mm' }}</h6>\n <i class=\"wi wi-owm-{{ itemValue('Weather_OWM_ConditionId_h' + hour) }}\" ng-style=\"{ 'color' : (config.icon_color_forecast == NULL ? primary-color : config.icon_color_forecast), 'font-size' : (config.icon_size_detail == NULL ? '1em' : config.icon_size_detail + 'em') }\"></i>\n <h5>{{ '%.0f' | sprintf:(+itemValue('Weather_OWM_Temp_h' + hour).split(' ')[0] || 0)}}{{ itemValue('Weather_OWM_Temp_h' + hour).split(' ')[1] }}</h5>\n </div>\n </div>\n </div>\n </div>\n <div ng-if=\"config.show_detail_6h_3days\" class=\"row owm-row-detail-forecast\">\n <div ng-app=\"\" ng-init=\"hours=['6','12','18','24','30','36','42','48','54','60','66','72']\">\n <div class=\"row owm-row-detail-header\">\n <div ng-repeat=\"hour in hours\">\n <div ng-if=\"((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') > 4) && ((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') < 11)\", class=\"col-xs-1 col-left-border\">\n <h4>{{ itemValue('Weather_OWM_DateTime_h' + hour) | date: 'EEE' }}</h4>\n </div>\n <div ng-if=\"((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') < 5) || ((itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH') > 10)\", class=\"col-xs-1\">\n <h4>&nbsp</h4>\n </div>\n </div>\n </div>\n <div class=\"row owm-row-detail-forecast\">\n <div ng-repeat=\"hour in hours\", class=\"col-xs-1 col-md-border\">\n <h6>{{ itemValue('Weather_OWM_DateTime_h' + hour) | date: 'HH:mm' }}</h6>\n <i class=\"wi wi-owm-{{ itemValue('Weather_OWM_ConditionId_h' + hour) }}\" ng-style=\"{ 'color' : (config.icon_color_forecast == NULL ? primary-color : config.icon_color_forecast), 'font-size' : (config.icon_size_detail == NULL ? '1em' : config.icon_size_detail + 'em') }\"></i>\n <h5>{{ '%.0f' | sprintf:(+itemValue('Weather_OWM_Temp_h' + hour).split(' ')[0] || 0)}}{{ itemValue('Weather_OWM_Temp_h' + hour).split(' ')[1] }}</h5>\n </div>\n </div>\n </div>\n </div>\n <div ng-if=\"config.show_4day_forecast\" class=\"row owm-row-forecast\">\n <div class=\"col-xs-3 col-md-border\">\n <h4 class=\"owm-to-upper\">{{ date_time0 | date:(config.day_format == NULL ? 'EEEE' : config.day_format) }}</h4>\n <i class=\"wi wi-owm-{{ condition_id0 }}\" ng-style=\"{ 'color' : (config.icon_color_forecast == NULL) ? primary-color : config.icon_color_forecast, 'font-size' : (config.icon_size_forecast == NULL) ? '3em' : config.icon_size_forecast + 'em' }\"></i>\n <h5 class=\"owm-condition owm-to-upper\">{{ condition0 }}</h5>\n <h4><b>{{ temp0 == NULL ? '' : '%.0f' | sprintf:(+temp0.split(' ')[0] || 0)}} {{temp0.split(' ')[1] }}</b></h4>\n </div>\n <div class=\"col-xs-3 col-md-border\">\n <h4 class=\"owm-to-upper\">{{ date_time1 | date:(config.day_format == NULL ? 'EEEE' : config.day_format) }}</h4>\n <i class=\"wi wi-owm-{{ condition_id1 }}\" ng-style=\"{ 'color' : (config.icon_color_forecast == NULL) ? primary-color : config.icon_color_forecast, 'font-size' : (config.icon_size_forecast == NULL) ? '3em' : config.icon_size_forecast + 'em' }\"></i>\n <h5 class=\"owm-condition owm-to-upper\">{{ condition1 }}</h5>\n <h4><b>{{ temp1 == NULL ? '' : '%.0f' | sprintf:(+temp1.split(' ')[0] || 0)}} {{temp1.split(' ')[1] }}</b></h4>\n </div>\n <div class=\"col-xs-3 col-md-border\">\n <h4 class=\"owm-to-upper\">{{ date_time2 | date:(config.day_format == NULL ? 'EEEE' : config.day_format) }}</h4>\n <i class=\"wi wi-owm-{{ condition_id2 }}\" ng-style=\"{ 'color' : (config.icon_color_forecast == NULL) ? primary-color : config.icon_color_forecast, 'font-size' : (config.icon_size_forecast == NULL) ? '3em' : config.icon_size_forecast + 'em' }\"></i>\n <h5 class=\"owm-condition owm-to-upper\">{{ condition2 }}</h5>\n <h4><b>{{ temp2 == NULL ? '' : '%.0f' | sprintf:(+temp2.split(' ')[0] || 0)}} {{temp2.split(' ')[1] }}</b></h4>\n </div>\n <div class=\"col-xs-3 col-md-border\">\n <h4 class=\"owm-to-upper\">{{ date_time3 | date:(config.day_format == NULL ? 'EEEE' : config.day_format) }}</h4>\n <i class=\"wi wi-owm-{{ condition_id3 }}\" ng-style=\"{ 'color' : (config.icon_color_forecast == NULL) ? primary-color : config.icon_color_forecast, 'font-size' : (config.icon_size_forecast == NULL) ? '3em' : config.icon_size_forecast + 'em' }\"></i>\n <h5 class=\"owm-condition owm-to-upper\">{{ condition3 }}</h5>\n <h4><b>{{ temp3 == NULL ? '' : '%.0f' | sprintf:(+temp3.split(' ')[0] || 0)}} {{temp3.split(' ')[1] }}</b></h4>\n </div>\n </div>\n </div>\n</div>\n",

@BasvanH
Copy link
Owner

BasvanH commented Jan 2, 2023

Thanks @LuiSauberhorn, I will update the widget with your suggestion.

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

No branches or pull requests

2 participants