Unit.pm 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553
  1. # $Id: Unit.pm 13272 2017-01-29 17:28:13Z loredo $
  2. use strict;
  3. use warnings;
  4. use Scalar::Util qw(looks_like_number);
  5. use UConv;
  6. use Data::Dumper;
  7. use utf8;
  8. use Encode qw(encode_utf8 decode_utf8);
  9. sub Unit_Initialize() {
  10. }
  11. # scale helper for metric numbers
  12. my $scales_m = {
  13. autoscale => {
  14. '0' => { format => '%i', scale => 1000, },
  15. '0.001' => { format => '%i', scale => 1000, },
  16. '0.1' => { format => '%.1f', scale => 1, },
  17. '10' => { format => '%i', scale => 1, },
  18. '1.0e3' => { format => '%.1f', scale => 0.001, },
  19. '2.0e3' => { format => '%i', scale => 0.001, },
  20. '1.0e6' => { format => '%.1f', scale => 0.001, },
  21. '2.0e6' => { format => '%i', scale => 0.001, },
  22. },
  23. '1.0e-12' => {
  24. 'scale_txt_m' => 'p',
  25. 'scale_txt_long_m' => {
  26. de => 'Piko',
  27. en => 'Pico',
  28. },
  29. },
  30. '1.0e-9' => {
  31. 'scale_txt_m' => 'n',
  32. 'scale_txt_long_m' => {
  33. de => 'Nano',
  34. en => 'Nano',
  35. },
  36. },
  37. '1.0e-6' => {
  38. 'scale_txt_m' => 'μ',
  39. 'scale_txt_long_m' => {
  40. de => 'Mikro',
  41. en => 'Micro',
  42. },
  43. },
  44. '1.0e-3' => {
  45. 'scale_txt_m' => 'm',
  46. 'scale_txt_long_m' => {
  47. de => 'Milli',
  48. en => 'Mili',
  49. },
  50. },
  51. '1.0e-2' => {
  52. 'scale_txt_m' => 'c',
  53. 'scale_txt_long_m' => {
  54. de => 'Zenti',
  55. en => 'Centi',
  56. },
  57. },
  58. '1.0e-1' => {
  59. 'scale_txt_m' => 'd',
  60. 'scale_txt_long_m' => {
  61. de => 'Dezi',
  62. en => 'Deci',
  63. },
  64. },
  65. '1.0e0' => {
  66. 'scale_txt_m' => '',
  67. 'scale_txt_long_m' => '',
  68. },
  69. '1.0e1' => {
  70. 'scale_txt_m' => 'da',
  71. 'scale_txt_long_m' => {
  72. de => 'Deka',
  73. en => 'Deca',
  74. },
  75. },
  76. '1.0e2' => {
  77. 'scale_txt_m' => 'h',
  78. 'scale_txt_long_m' => {
  79. de => 'Hekto',
  80. en => 'Hecto',
  81. },
  82. },
  83. '1.0e3' => {
  84. 'scale_txt_m' => 'k',
  85. 'scale_txt_long_m' => {
  86. de => 'Kilo',
  87. en => 'Kilo',
  88. },
  89. },
  90. '1.0e6' => {
  91. 'scale_txt_m' => 'M',
  92. 'scale_txt_long_m' => {
  93. de => 'Mega',
  94. en => 'Mega',
  95. },
  96. },
  97. '1.0e9' => {
  98. 'scale_txt_m' => 'G',
  99. 'scale_txt_long_m' => {
  100. de => 'Giga',
  101. en => 'Giga',
  102. },
  103. },
  104. '1.0e12' => {
  105. 'scale_txt_m' => 'T',
  106. 'scale_txt_long_m' => {
  107. de => 'Tera',
  108. en => 'Tera',
  109. },
  110. },
  111. '1.0e15' => {
  112. 'scale_txt_m' => 'P',
  113. 'scale_txt_long_m' => {
  114. de => 'Peta',
  115. en => 'Peta',
  116. },
  117. },
  118. };
  119. # scale helper for metric square numbers
  120. my $scales_sq = {
  121. 'scale_txt_sq' => chr(0x00B2),
  122. 'scale_txt_long_sq' => {
  123. de => 'Quadrat',
  124. en => 'Square',
  125. },
  126. };
  127. # scale helper for metric cubic numbers
  128. my $scales_cu = {
  129. 'scale_txt_cu' => chr(0x00B3),
  130. 'scale_txt_long_cu' => {
  131. de => 'Kubik',
  132. en => 'Cubic',
  133. },
  134. };
  135. # scale helper for time related numbers
  136. my $scales_t = {
  137. # second
  138. 's' => {
  139. 'scale_txt_t' => 's',
  140. 'scale_txt_long_t' => {
  141. de => 'Sekunde',
  142. en => 'second',
  143. },
  144. 'scale_txt_long_pl_t' => {
  145. de => 'Sekunden',
  146. en => 'seconds',
  147. },
  148. },
  149. # minute
  150. 'min' => {
  151. 'scale_txt_t' => {
  152. de => 'Min',
  153. en => 'min',
  154. },
  155. 'scale_txt_long_t' => {
  156. de => 'Minute',
  157. en => 'minute',
  158. },
  159. 'scale_txt_long_pl_t' => {
  160. de => 'Minuten',
  161. en => 'minutes',
  162. },
  163. },
  164. # hour
  165. 'h' => {
  166. 'scale_txt_t' => 'h',
  167. 'scale_txt_long_t' => {
  168. de => 'Stunde',
  169. en => 'hour',
  170. },
  171. 'scale_txt_long_pl_t' => {
  172. de => 'Stunden',
  173. en => 'hours',
  174. },
  175. },
  176. # day
  177. 'd' => {
  178. 'scale_txt_t' => 'd',
  179. 'scale_txt_long_t' => {
  180. de => 'Tag',
  181. en => 'day',
  182. },
  183. 'scale_txt_long_pl_t' => {
  184. de => 'Tage',
  185. en => 'days',
  186. },
  187. },
  188. # week
  189. 'w' => {
  190. 'scale_txt_t' => 'w',
  191. 'scale_txt_long_t' => {
  192. de => 'Woche',
  193. en => 'week',
  194. },
  195. 'scale_txt_long_pl_t' => {
  196. de => 'Wochen',
  197. en => 'weeks',
  198. },
  199. },
  200. # month
  201. 'm' => {
  202. 'scale_txt_t' => 'm',
  203. 'scale_txt_long_t' => {
  204. de => 'Monat',
  205. en => 'month',
  206. },
  207. 'scale_txt_long_pl_t' => {
  208. de => 'Monate',
  209. en => 'month',
  210. },
  211. },
  212. # year
  213. 'a' => {
  214. 'scale_txt_t' => 'a',
  215. 'scale_txt_long_t' => {
  216. de => 'Jahr',
  217. en => 'year',
  218. },
  219. 'scale_txt_long_pl_t' => {
  220. de => 'Jahre',
  221. en => 'years',
  222. },
  223. },
  224. };
  225. # scale helper for time related numbers
  226. # Overall structure/grouping based on
  227. # https://de.wikipedia.org/wiki/Liste_physikalischer_Gr%C3%B6%C3%9Fen
  228. #
  229. # Scientific range: 0 - 99
  230. # FHEM Builtin range: 900 - 998
  231. # FHEM User Defined range: >= 999
  232. #
  233. # rtype_base => reference to base rtype in $rtypes used for
  234. # automatic unit conversion
  235. my $rtype_base = {
  236. 0 => {
  237. dimension => 'L',
  238. formula_symbol => 'l',
  239. rtype_base => 'm',
  240. base_description => {
  241. de => 'Länge',
  242. en => 'length',
  243. },
  244. format => '%.0f',
  245. decimal_mark => {
  246. de => 2,
  247. en => 1,
  248. },
  249. scope => { minValue => 0 },
  250. },
  251. 1 => {
  252. dimension => 'M',
  253. formula_symbol => 'm',
  254. rtype_base => 'kg',
  255. base_description => {
  256. de => 'Masse',
  257. en => 'mass',
  258. },
  259. format => '%.0f',
  260. decimal_mark => {
  261. de => 2,
  262. en => 1,
  263. },
  264. scope => { minValue => 0 },
  265. },
  266. 2 => {
  267. dimension => 'T',
  268. formula_symbol => 't',
  269. rtype_base => 's',
  270. base_description => {
  271. de => 'Zeit',
  272. en => 'time',
  273. },
  274. format => '%.0f',
  275. decimal_mark => {
  276. de => 2,
  277. en => 1,
  278. },
  279. scope => { minValue => 0 },
  280. },
  281. 3 => {
  282. dimension => 'I',
  283. formula_symbol => 'i',
  284. rtype_base => 'a',
  285. base_description => {
  286. de => 'elektrische Stromstärke',
  287. en => 'electric current',
  288. },
  289. format => '%.1f',
  290. decimal_mark => {
  291. de => 2,
  292. en => 1,
  293. },
  294. scope => { minValue => 0 },
  295. },
  296. 4 => {
  297. dimension => 'θ',
  298. formula_symbol => 'T',
  299. rtype_base => 'k',
  300. base_description => {
  301. de => 'absolute Temperatur',
  302. en => 'absolute temperature',
  303. },
  304. format => '%.1f',
  305. decimal_mark => {
  306. de => 2,
  307. en => 1,
  308. },
  309. scope => { minValue => 0 },
  310. },
  311. 5 => {
  312. dimension => 'N',
  313. formula_symbol => 'n',
  314. rtype_base => 'mol',
  315. base_description => {
  316. de => 'Stoffmenge',
  317. en => 'amount of substance',
  318. },
  319. format => '%.1f',
  320. decimal_mark => {
  321. de => 2,
  322. en => 1,
  323. },
  324. scope => { minValue => 0 },
  325. },
  326. 6 => {
  327. dimension => 'J',
  328. formula_symbol => 'Iv',
  329. rtype_base => 'cd',
  330. base_description => {
  331. de => 'Lichtstärke',
  332. en => 'luminous intensity',
  333. },
  334. format => '%.1f',
  335. decimal_mark => {
  336. de => 2,
  337. en => 1,
  338. },
  339. scope => { minValue => 0 },
  340. },
  341. 7 => {
  342. dimension => 'M L^2 T^−2',
  343. formula_symbol => 'E',
  344. rtype_base => 'j',
  345. base_description => {
  346. de => 'Energie',
  347. en => 'energy',
  348. },
  349. format => '%.1f',
  350. decimal_mark => {
  351. de => 2,
  352. en => 1,
  353. },
  354. scope => { minValue => 0 },
  355. },
  356. 8 => {
  357. dimension => 'T^−1',
  358. formula_symbol => 'f',
  359. rtype_base => 'hz',
  360. base_description => {
  361. de => 'Frequenz',
  362. en => 'frequency',
  363. },
  364. format => '%i',
  365. decimal_mark => {
  366. de => 2,
  367. en => 1,
  368. },
  369. scope => { minValue => 0 },
  370. },
  371. 9 => {
  372. dimension => 'M L^2 T^−3',
  373. formula_symbol => 'P',
  374. rtype_base => 'w',
  375. base_description => {
  376. de => 'Leistung',
  377. en => 'power',
  378. },
  379. format => '%.1f',
  380. decimal_mark => {
  381. de => 2,
  382. en => 1,
  383. },
  384. scope => { minValue => 0 },
  385. },
  386. 10 => {
  387. dimension => 'M L^−1 T^−2',
  388. formula_symbol => 'p',
  389. rtype_base => 'pa',
  390. base_description => {
  391. de => 'Druck',
  392. en => 'pressure',
  393. },
  394. format => '%i',
  395. decimal_mark => {
  396. de => 2,
  397. en => 1,
  398. },
  399. scope => { minValue => 0 },
  400. },
  401. 11 => {
  402. dimension => 'M L^−1 T^−2',
  403. formula_symbol => 'pabs',
  404. rtype_base => 'pabs',
  405. base_description => {
  406. de => 'absoluter Druck',
  407. en => 'absolute pressure',
  408. },
  409. format => '%i',
  410. decimal_mark => {
  411. de => 2,
  412. en => 1,
  413. },
  414. scope => { minValue => 0 },
  415. },
  416. 12 => {
  417. dimension => 'M L^−1 T^−2',
  418. formula_symbol => 'pamb',
  419. rtype_base => 'pamb',
  420. base_description => {
  421. de => 'Luftdruck',
  422. en => 'air pressure',
  423. },
  424. format => '%i',
  425. decimal_mark => {
  426. de => 2,
  427. en => 1,
  428. },
  429. scope => { minValue => 0 },
  430. },
  431. 13 => {
  432. dimension => 'M L^2 T^−3 I^−1',
  433. formula_symbol => 'U',
  434. rtype_base => 'v',
  435. base_description => {
  436. de => 'elektrische Spannung',
  437. en => 'electric voltage',
  438. },
  439. format => '%.1f',
  440. decimal_mark => {
  441. de => 2,
  442. en => 1,
  443. },
  444. scope => { minValue => 0 },
  445. },
  446. 14 => {
  447. dimension => '1',
  448. formula_symbol => '',
  449. rtype_base => 'rad',
  450. base_description => {
  451. de => 'ebener Winkel',
  452. en => 'plane angular',
  453. },
  454. format => '%i',
  455. decimal_mark => {
  456. de => 2,
  457. en => 1,
  458. },
  459. scope => { minValue => 0 },
  460. },
  461. 15 => {
  462. dimension => 'L T^−1',
  463. formula_symbol => 'v',
  464. rtype_base => 'kmph',
  465. base_description => {
  466. de => 'Geschwindigkeit',
  467. en => 'speed',
  468. },
  469. format => '%i',
  470. decimal_mark => {
  471. de => 2,
  472. en => 1,
  473. },
  474. scope => { minValue => 0 },
  475. },
  476. 16 => {
  477. dimension => 'L^−2 J',
  478. formula_symbol => 'Ev',
  479. rtype_base => 'lx',
  480. base_description => {
  481. de => 'Beleuchtungsstärke',
  482. en => 'illumination intensity',
  483. },
  484. format => '%i',
  485. decimal_mark => {
  486. de => 2,
  487. en => 1,
  488. },
  489. scope => { minValue => 0 },
  490. },
  491. 17 => {
  492. dimension => 'J',
  493. formula_symbol => 'F',
  494. rtype_base => 'lm',
  495. base_description => {
  496. de => 'Lichtstrom',
  497. en => 'luminous flux',
  498. },
  499. format => '%i',
  500. decimal_mark => {
  501. de => 2,
  502. en => 1,
  503. },
  504. scope => { minValue => 0 },
  505. },
  506. 18 => {
  507. dimension => 'L^3',
  508. formula_symbol => 'V',
  509. rtype_base => 'm3',
  510. base_description => {
  511. de => 'Volumen',
  512. en => 'volume',
  513. },
  514. format => '%i',
  515. decimal_mark => {
  516. de => 2,
  517. en => 1,
  518. },
  519. scope => { minValue => 0 },
  520. },
  521. 19 => {
  522. dimension => '1',
  523. formula_symbol => 'B',
  524. rtype_base => 'b',
  525. base_description => {
  526. de => 'Logarithmische Größe',
  527. en => 'logarithmic level',
  528. },
  529. format => '%.1f',
  530. decimal_mark => {
  531. de => 2,
  532. en => 1,
  533. },
  534. scope => { minValue => 0 },
  535. },
  536. 20 => {
  537. dimension => 'I T',
  538. formula_symbol => 'C',
  539. rtype_base => 'coul',
  540. base_description => {
  541. de => 'elektrische Ladung',
  542. en => 'electric charge',
  543. },
  544. format => '%.1f',
  545. decimal_mark => {
  546. de => 2,
  547. en => 1,
  548. },
  549. scope => { minValue => 0 },
  550. },
  551. 21 => {
  552. dimension => '',
  553. formula_symbol => 'F',
  554. rtype_base => 'far',
  555. base_description => {
  556. de => 'elektrische Kapazität',
  557. en => 'electric capacity',
  558. },
  559. format => '%.1f',
  560. decimal_mark => {
  561. de => 2,
  562. en => 1,
  563. },
  564. scope => { minValue => 0 },
  565. },
  566. 22 => {
  567. dimension => 'M L2 T−3 I−2',
  568. formula_symbol => 'R',
  569. rtype_base => 'ohm',
  570. base_description => {
  571. de => 'elektrischer Widerstand',
  572. en => 'electric resistance',
  573. },
  574. format => '%.1f',
  575. decimal_mark => {
  576. de => 2,
  577. en => 1,
  578. },
  579. scope => { minValue => 0 },
  580. },
  581. 23 => {
  582. dimension => 'L^2',
  583. formula_symbol => 'A',
  584. rtype_base => 'm2',
  585. base_description => {
  586. de => 'Flächeninhalt',
  587. en => 'surface area',
  588. },
  589. format => '%i',
  590. decimal_mark => {
  591. de => 2,
  592. en => 1,
  593. },
  594. scope => { minValue => 0 },
  595. },
  596. 24 => {
  597. base_description => {
  598. de => 'Währung',
  599. en => 'currency',
  600. },
  601. format => '%.2f',
  602. decimal_mark => {
  603. de => 2,
  604. en => 1,
  605. },
  606. scope => '^[0-9]*(?:\.[0-9]*)?$',
  607. },
  608. 25 => {
  609. base_description => {
  610. de => 'Zahlen',
  611. en => 'Numbering',
  612. },
  613. format => '%.1f',
  614. decimal_mark => {
  615. de => 2,
  616. en => 1,
  617. },
  618. tmpl => '%value%',
  619. },
  620. 26 => {
  621. base_description => {
  622. de => 'Logische Operatoren',
  623. en => 'Logical operators',
  624. },
  625. tmpl => '%value%',
  626. },
  627. 900 => {
  628. base_description => 'FHEM Builtin Readings Type',
  629. tmpl => '%value%',
  630. },
  631. 999 => {
  632. base_description => 'FHEM User Defined Readings Type',
  633. tmpl => '%value%',
  634. },
  635. };
  636. # FHEM built-in reading types (RType).
  637. # Values will be combined into a new super-hash using
  638. # cross-references to $rtype_base, $scales_m, $scales_sq, $scales_cu, $scales_t
  639. #
  640. # ref_base => reference to $rtype_base id to include it's keys here
  641. # ref_sq => include keys from $scales_sq here; normally combined with a scale_sq reference as well
  642. # ref_cu => include keys from $scales_cu here; normally combined with a scale_cu reference as well
  643. # ref_t => reference to $scales_t id to include it's keys here; ; normally combined with a scale_t reference as well
  644. # ref => self-reference to $rtype id to include it's keys here (RType alias helper)
  645. my $rtypes = {
  646. # others
  647. url => {
  648. ref_base => 900,
  649. rtype_description => 'General URL including protocol prefix',
  650. tmpl => '<html><a href="%value%">%value%</a></html>',
  651. },
  652. url_http => {
  653. ref_base => 900,
  654. rtype_description => 'HTTP/S URL w/ or w/o protocol prefix',
  655. tmpl => '<html><a href="%value%">%value%</a></html>',
  656. },
  657. trend => {
  658. ref_base => 900,
  659. symbol => [ chr(0x2B0C), chr(0x2B08), chr(0x2B0A) ],
  660. txt => [ '=', '+', '-' ],
  661. txt_long => {
  662. de => [ 'gleichbleibend', 'steigend', 'fallend' ],
  663. en => [ 'steady', 'rising', 'falling' ],
  664. fr => [ 'stable', 'croissant', 'décroissant' ],
  665. nl => [ 'stabiel', 'stijgend', 'dalend' ],
  666. pl => [ 'stabilne', 'rośnie', 'spada' ],
  667. },
  668. scope => [
  669. '^(=|steady|stable|0)$', '^(\+|rising|up|1)$',
  670. '^(-|falling|down|2)$'
  671. ],
  672. tmpl => '%symbol%',
  673. tmpl_long => '%txt_long%',
  674. rtype_description => 'Trend',
  675. },
  676. oknok => {
  677. ref_base => 900,
  678. txt => {
  679. de => [ 'Fehler', 'ok', 'Warnung' ],
  680. en => [ 'error', 'ok', 'warning' ],
  681. },
  682. scope => [
  683. '^(nok|error|dead|invalid|0)$', '^(ok|alive|valid|1)$',
  684. '^(warning|warn|low|2)$', '^(.*)$'
  685. ],
  686. rtype_description => {
  687. de =>
  688. 'Fehlerstatus; siehe RType roknok, sofern 0<>1 vertauschte Bedeutung haben',
  689. en => 'error state',
  690. },
  691. },
  692. roknok => {
  693. ref_base => 900,
  694. txt => {
  695. de => [ 'Fehler', 'ok', 'Warnung' ],
  696. en => [ 'error', 'ok', 'warning' ],
  697. },
  698. scope => [
  699. '^(nok|error|dead|invalid|1)$', '^(ok|alive|valid|0)$',
  700. '^(warning|warn|low|2)$', '^(.*)$'
  701. ],
  702. rtype_description => {
  703. de =>
  704. 'verdrehter Fehlerstatus, bei dem 0=ok und 1=Fehler bedeutet; Gegenteil von RType oknok',
  705. en => 'reversed error state',
  706. },
  707. },
  708. onoff => {
  709. ref_base => 900,
  710. txt => {
  711. de => [ 'aus', 'an', 'nicht verfügbar' ],
  712. en => [ 'off', 'on', 'absent' ],
  713. },
  714. scope =>
  715. [ '^(off|no|standby|0)$', '^(on|yes|1)$', '^(absent|offline|2)$', ],
  716. rtype_description => {
  717. de => 'Schaltstatus',
  718. en => 'Switch state',
  719. },
  720. },
  721. reachable => {
  722. ref_base => 900,
  723. txt => {
  724. de => [ 'nicht verfügbar', 'verfügbar' ],
  725. en => [ 'unavailable', 'available' ],
  726. },
  727. scope => [
  728. '^(unavailable|absent|disappeared|false|no|0)$',
  729. '^(available|present|appeared|true|yes|1)$'
  730. ],
  731. rtype_description => {
  732. de => 'Verfügbarkeit/Erreichbarkeit',
  733. en => 'availability/reachability',
  734. },
  735. },
  736. weekday => {
  737. ref_base => 900,
  738. symbol => {
  739. de => [ 'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa' ],
  740. en => [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
  741. },
  742. txt => {
  743. de => [ 'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa' ],
  744. en => [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
  745. },
  746. txt_long => {
  747. de => [
  748. 'Sonntag', 'Montag', 'Dienstag', 'Mittwoch',
  749. 'Donnerstag', 'Freitag', 'Samstag'
  750. ],
  751. en => [
  752. 'Sunday', 'Monday', 'Tuesday', 'Wednesday',
  753. 'Thursday', 'Friday', 'Saturday'
  754. ],
  755. },
  756. scope => {
  757. de => [
  758. '^(So|Son|Sonntag|0)$', '^(Mo|Mon|Montag|1)$',
  759. '^(Di|Die|Dienstag|2)$', '^(Mi|Mit|Mittwoch|3)$',
  760. '^(Do|Don|Donnerstag|4)$', '^(Fr|Fre|Freitag|5)$',
  761. '^(Sa|Sam|Samstag|6)$'
  762. ],
  763. en => [
  764. '^(Sun|Su|Sunday|0)$', '^(Mon|Mo|Monday|1)$',
  765. '^(Tue|Tu|Tuesday|2)$', '^(Wed|We|Wednesday|3)$',
  766. '^(Thu|Th|Thursday|4)$', '^(Fri|Fr|Friday|5)$',
  767. '^(Sat|Sa|Saturday|6)$'
  768. ],
  769. },
  770. tmpl => '%txt%',
  771. tmpl_long => '%txt_long%',
  772. rtype_description => {
  773. de =>
  774. 'Wochentag nach englisch-amerikanischer Annahme des Wochenstarts am Sonntag',
  775. en =>
  776. 'Day of the week according to english assumption for the week to start on sunday',
  777. },
  778. },
  779. weekday_iso => {
  780. ref_base => 900,
  781. symbol => {
  782. de => [ 'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa' ],
  783. en => [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
  784. },
  785. txt => {
  786. de => [ 'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa' ],
  787. en => [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
  788. },
  789. txt_long => {
  790. de => [
  791. 'Sonntag', 'Montag', 'Dienstag', 'Mittwoch',
  792. 'Donnerstag', 'Freitag', 'Samstag'
  793. ],
  794. en => [
  795. 'Sunday', 'Monday', 'Tuesday', 'Wednesday',
  796. 'Thursday', 'Friday', 'Saturday'
  797. ],
  798. },
  799. scope => {
  800. de => [
  801. '^(So|Son|Sonntag|6)$', '^(Mo|Mon|Montag|0)$',
  802. '^(Di|Die|Dienstag|1)$', '^(Mi|Mit|Mittwoch|2)$',
  803. '^(Do|Don|Donnerstag|3)$', '^(Fr|Fre|Freitag|4)$',
  804. '^(Sa|Sam|Samstag|5)$'
  805. ],
  806. en => [
  807. '^(Sun|Su|Sunday|6)$', '^(Mon|Mo|Monday|0)$',
  808. '^(Tue|Tu|Tuesday|1)$', '^(Wed|We|Wednesday|2)$',
  809. '^(Thu|Th|Thursday|3)$', '^(Fri|Fr|Friday|4)$',
  810. '^(Sat|Sa|Saturday|5)$'
  811. ],
  812. },
  813. tmpl => '%txt%',
  814. tmpl_long => '%txt_long%',
  815. rtype_description => {
  816. de => 'Wochentag nach ISO-Standard, Woche beginnend am Montag',
  817. en =>
  818. 'Day of the week according to ISO standard, week beginning on Mondays',
  819. },
  820. },
  821. weekday_night => {
  822. ref_base => 900,
  823. symbol => {
  824. de => [ 'So N', 'Mo N', 'Di N', 'Mi N', 'Do N', 'Fr N', 'Sa N' ],
  825. en => [
  826. 'Sun N', 'Mon N', 'Tue N', 'Wed N', 'Thu N', 'Fri N ', 'Sat N'
  827. ],
  828. },
  829. txt => {
  830. de => [ 'So N', 'Mo N', 'Di N', 'Mi N', 'Do N', 'Fr N', 'Sa N' ],
  831. en => [
  832. 'Sun N', 'Mon N', 'Tue N', 'Wed N', 'Thu N', 'Fri N ', 'Sat N'
  833. ],
  834. },
  835. txt_long => {
  836. de => [
  837. 'Sonntag Nacht',
  838. 'Montag Nacht',
  839. 'Dienstag Nacht',
  840. 'Mittwoch Nacht',
  841. 'Donnerstag Nacht',
  842. 'Freitag Nacht',
  843. 'Samstag Nacht'
  844. ],
  845. en => [
  846. 'Sunday Night',
  847. 'Monday Night',
  848. 'Tuesday Night',
  849. 'Wednesday Night',
  850. 'Thursday Night',
  851. 'Friday Night',
  852. 'Saturday Night'
  853. ],
  854. },
  855. scope => {
  856. de => [
  857. '^(\s*(Nacht|Na)?\s*(So|Son|Sonntag|0)\s*(Nacht|Na)?\s*)$',
  858. '^(\s*(Nacht|Na)?\s*(Mo|Mon|Montag|1)\s*(Nacht|Na)?\s*)$',
  859. '^(\s*(Nacht|Na)?\s*(Di|Die|Dienstag|2)\s*(Nacht|Na)?\s*)$',
  860. '^(\s*(Nacht|Na)?\s*(Mi|Mit|Mittwoch|3)\s*(Nacht|Na)?\s*)$',
  861. '^(\s*(Nacht|Na)?\s*(Do|Don|Donnerstag|4)\s*(Nacht|Na)?\s*)$',
  862. '^(\s*(Nacht|Na)?\s*(Fr|Fre|Freitag|5)\s*(Nacht|Na)?\s*)$',
  863. '^(\s*(Nacht|Na)?\s*(Sa|Sam|Samstag|6)\s*(Nacht|Na)?\s*)$'
  864. ],
  865. en => [
  866. '^(\s*(Night|Na)?\s*(Sun|Su|Sunday|0)\s*(Night|Na)?\s*)$',
  867. '^(\s*(Night|Na)?\s*(Mon|Mo|Monday|1)\s*(Night|Na)?\s*)$',
  868. '^(\s*(Night|Na)?\s*(Tue|Tu|Tuesday|2)\s*(Night|Na)?\s*)$',
  869. '^(\s*(Night|Na)?\s*(Wed|We|Wednesday|3)\s*(Night|Na)?\s*)$',
  870. '^(\s*(Night|Na)?\s*(Thu|Th|Thursday|4)\s*(Night|Na)?\s*)$',
  871. '^(\s*(Night|Na)?\s*(Fri|Fr|Friday|5)\s*(Night|Na)?\s*)$',
  872. '^(\s*(Night|Na)?\s*(Sat|Sa|Saturday|6)\s*(Night|Na)?\s*)$'
  873. ],
  874. },
  875. tmpl => '%txt%',
  876. tmpl_long => '%txt_long%',
  877. rtype_description => {
  878. de =>
  879. 'Nächtlicher Wochentag nach englisch-amerikanischem Standard des Wochenstarts am Sonntag',
  880. en =>
  881. 'Nightly day of the week according to english standard for the week to start on sunday',
  882. },
  883. },
  884. weekday_night_iso => {
  885. ref_base => 900,
  886. symbol => {
  887. de => [ 'So N', 'Mo N', 'Di N', 'Mi N', 'Do N', 'Fr N', 'Sa N' ],
  888. en => [
  889. 'Sun N', 'Mon N', 'Tue N', 'Wed N', 'Thu N', 'Fri N ', 'Sat N'
  890. ],
  891. },
  892. txt => {
  893. de => [ 'So N', 'Mo N', 'Di N', 'Mi N', 'Do N', 'Fr N', 'Sa N' ],
  894. en => [
  895. 'Sun N', 'Mon N', 'Tue N', 'Wed N', 'Thu N', 'Fri N ', 'Sat N'
  896. ],
  897. },
  898. txt_long => {
  899. de => [
  900. 'Sonntag Nacht',
  901. 'Montag Nacht',
  902. 'Dienstag Nacht',
  903. 'Mittwoch Nacht',
  904. 'Donnerstag Nacht',
  905. 'Freitag Nacht',
  906. 'Samstag Nacht'
  907. ],
  908. en => [
  909. 'Sunday Night',
  910. 'Monday Night',
  911. 'Tuesday Night',
  912. 'Wednesday Night',
  913. 'Thursday Night',
  914. 'Friday Night',
  915. 'Saturday Night'
  916. ],
  917. },
  918. scope => {
  919. de => [
  920. '^(\s*(Nacht|Na)?\s*(So|Son|Sonntag|6)\s*(Nacht|Na)?\s*)$',
  921. '^(\s*(Nacht|Na)?\s*(Mo|Mon|Montag|0)\s*(Nacht|Na)?\s*)$',
  922. '^(\s*(Nacht|Na)?\s*(Di|Die|Dienstag|1)\s*(Nacht|Na)?\s*)$',
  923. '^(\s*(Nacht|Na)?\s*(Mi|Mit|Mittwoch|2)\s*(Nacht|Na)?\s*)$',
  924. '^(\s*(Nacht|Na)?\s*(Do|Don|Donnerstag|3)\s*(Nacht|Na)?\s*)$',
  925. '^(\s*(Nacht|Na)?\s*(Fr|Fre|Freitag|4)\s*(Nacht|Na)?\s*)$',
  926. '^(\s*(Nacht|Na)?\s*(Sa|Sam|Samstag|5)\s*(Nacht|Na)?\s*)$'
  927. ],
  928. en => [
  929. '^(\s*(Night|Na)?\s*(Sun|Su|Sunday|6)\s*(Night|Na)?\s*)$',
  930. '^(\s*(Night|Na)?\s*(Mon|Mo|Monday|0)\s*(Night|Na)?\s*)$',
  931. '^(\s*(Night|Na)?\s*(Tue|Tu|Tuesday|1)\s*(Night|Na)?\s*)$',
  932. '^(\s*(Night|Na)?\s*(Wed|We|Wednesday|2)\s*(Night|Na)?\s*)$',
  933. '^(\s*(Night|Na)?\s*(Thu|Th|Thursday|3)\s*(Night|Na)?\s*)$',
  934. '^(\s*(Night|Na)?\s*(Fri|Fr|Friday|4)\s*(Night|Na)?\s*)$',
  935. '^(\s*(Night|Na)?\s*(Sat|Sa|Saturday|5)\s*(Night|Na)?\s*)$'
  936. ],
  937. },
  938. tmpl => '%txt%',
  939. tmpl_long => '%txt_long%',
  940. rtype_description => {
  941. de =>
  942. 'Nächtlicher Wochentag nach ISO-Standard, Woche beginnend am Montag',
  943. en =>
  944. 'Nightly day of the week according to ISO standard, week beginning on Mondays',
  945. },
  946. },
  947. direction => {
  948. ref_base => 900,
  949. formula_symbol => 'Dir',
  950. ref => 'gon',
  951. scope => { minValue => 0, maxValue => 360 },
  952. rtype_description => {
  953. de => 'Richtungsangabe',
  954. en => 'direction',
  955. },
  956. },
  957. compasspoint => {
  958. ref_base => 900,
  959. formula_symbol => 'CP',
  960. ref => 'gon',
  961. txt => {
  962. de => [
  963. 'N', 'NNO', 'NO', 'ONO', 'O', 'OSO', 'SO', 'SSO',
  964. 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'
  965. ],
  966. en => [
  967. 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
  968. 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'
  969. ],
  970. },
  971. txt_long => {
  972. de => [
  973. 'Norden', 'Nord-Nordost', 'Nordost', 'Ost-Nordost',
  974. 'Osten', 'Ost-Südost', 'Südost', 'Süd-Südost',
  975. 'Süden', 'Süd-Südwest', 'Südwest', 'West-Südwest',
  976. 'Westen', 'West-Nordwest', 'Nordwest', 'Nord-Nordwest'
  977. ],
  978. en => [
  979. 'North', 'North-Northeast',
  980. 'Northeast', 'East-Northeast',
  981. 'East', 'East-Southeast',
  982. 'Southeast', 'South-Southeast',
  983. 'South', 'South-Southwest',
  984. 'Southwest', 'West-Southwest',
  985. 'West', 'West-Northwest',
  986. 'Northwest', 'North-Northwest'
  987. ],
  988. },
  989. scope => {
  990. de => [
  991. {
  992. ge => 0.0,
  993. lt => 22.5,
  994. eq => 360,
  995. regex => '^(N|Norden|0)$',
  996. value_num => 0.0,
  997. },
  998. {
  999. ge => 22.5,
  1000. lt => 45.0,
  1001. regex => '^(NNO|Nord-Nordost|1)$',
  1002. value_num => 22.5,
  1003. },
  1004. {
  1005. ge => 45.0,
  1006. lt => 67.5,
  1007. regex => '^(NO|Nordost|2)$',
  1008. value_num => 45.0,
  1009. },
  1010. {
  1011. ge => 67.5,
  1012. lt => 90.0,
  1013. regex => '^(ONO|Ost-Nordost|3)$',
  1014. value_num => 67.5,
  1015. },
  1016. {
  1017. ge => 90.0,
  1018. lt => 112.5,
  1019. regex => '^(O|Osten|4)$',
  1020. value_num => 90.0,
  1021. },
  1022. {
  1023. ge => 112.5,
  1024. lt => 135.0,
  1025. regex => '^(OSO|Ost-S(ü|u|ue)dost|5)$',
  1026. value_num => 112.5,
  1027. },
  1028. {
  1029. ge => 135.0,
  1030. lt => 157.5,
  1031. regex => '^(SO|S(ü|u|ue)dost|6)$',
  1032. value_num => 135.0,
  1033. },
  1034. {
  1035. ge => 157.5,
  1036. lt => 180.0,
  1037. regex => '^(SSO|S(ü|u|ue)d-S(ü|u|ue)dost|7)$',
  1038. value_num => 157.5,
  1039. },
  1040. {
  1041. ge => 180.0,
  1042. lt => 202.5,
  1043. regex => '^(S|S(ü|u|ue)den|8)$',
  1044. value_num => 180.0,
  1045. },
  1046. {
  1047. ge => 202.5,
  1048. lt => 225.0,
  1049. regex => '^(SSW|S(ü|u|ue)d-S(ü|u|ue)dwest|9)$',
  1050. value_num => 202.5,
  1051. },
  1052. {
  1053. ge => 225.0,
  1054. lt => 247.5,
  1055. regex => '^(SW|S(ü|u|ue)dwest|10)$',
  1056. value_num => 225.0,
  1057. },
  1058. {
  1059. ge => 247.5,
  1060. lt => 270.0,
  1061. regex => '^(WSW|West-S(ü|u|ue)dwest|11)$',
  1062. value_num => 247.5,
  1063. },
  1064. {
  1065. ge => 270.0,
  1066. lt => 292.5,
  1067. regex => '^(W|Westen|12)$',
  1068. value_num => 270.0,
  1069. },
  1070. {
  1071. ge => 292.5,
  1072. lt => 315.0,
  1073. regex => '^(WNW|West-Nordwest|13)$',
  1074. value_num => 292.5,
  1075. },
  1076. {
  1077. ge => 315.0,
  1078. lt => 337.5,
  1079. regex => '^(NW|Nordwest|14)$',
  1080. value_num => 315.0,
  1081. },
  1082. {
  1083. ge => 337.5,
  1084. lt => 360,
  1085. regex => '^(NNW|Nord-Nordwest|15)$',
  1086. value_num => 337.5,
  1087. },
  1088. ],
  1089. en => [
  1090. {
  1091. ge => 0.0,
  1092. lt => 22.5,
  1093. eq => 360,
  1094. regex => '^(N|North|0)$',
  1095. value_num => 0.0,
  1096. },
  1097. {
  1098. ge => 22.5,
  1099. lt => 45.0,
  1100. regex => '^(NNE|North-Northeast|1)$',
  1101. value_num => 22.5,
  1102. },
  1103. {
  1104. ge => 45.0,
  1105. lt => 67.5,
  1106. regex => '^(NE|Northeast|2)$',
  1107. value_num => 45.0,
  1108. },
  1109. {
  1110. ge => 67.5,
  1111. lt => 90.0,
  1112. regex => '^(ENE|East-Northeast|3)$',
  1113. value_num => 67.5,
  1114. },
  1115. {
  1116. ge => 90.0,
  1117. lt => 112.5,
  1118. regex => '^(E|East|4)$',
  1119. value_num => 90.0,
  1120. },
  1121. {
  1122. ge => 112.5,
  1123. lt => 135.0,
  1124. regex => '^(ESE|East-Southeast|5)$',
  1125. value_num => 112.5,
  1126. },
  1127. {
  1128. ge => 135.0,
  1129. lt => 157.5,
  1130. regex => '^(SE|Southeast|6)$',
  1131. value_num => 135.0,
  1132. },
  1133. {
  1134. ge => 157.5,
  1135. lt => 180.0,
  1136. regex => '^(SSE|South-Southeast|7)$',
  1137. value_num => 157.5,
  1138. },
  1139. {
  1140. ge => 180.0,
  1141. lt => 202.5,
  1142. regex => '^(S|South|8)$',
  1143. value_num => 180.0,
  1144. },
  1145. {
  1146. ge => 202.5,
  1147. lt => 225.0,
  1148. regex => '^(SSW|South-Southwest|9)$',
  1149. value_num => 202.5,
  1150. },
  1151. {
  1152. ge => 225.0,
  1153. lt => 247.5,
  1154. regex => '^(SW|Southwest|10)$',
  1155. value_num => 225.0,
  1156. },
  1157. {
  1158. ge => 247.5,
  1159. lt => 270.0,
  1160. regex => '^(WSW|West-Southwest|11)$',
  1161. value_num => 247.5,
  1162. },
  1163. {
  1164. ge => 270.0,
  1165. lt => 292.5,
  1166. regex => '^(W|West|12)$',
  1167. value_num => 270.0,
  1168. },
  1169. {
  1170. ge => 292.5,
  1171. lt => 315.0,
  1172. regex => '^(WNW|West-Northwest|13)$',
  1173. value_num => 292.5,
  1174. },
  1175. {
  1176. ge => 315.0,
  1177. lt => 337.5,
  1178. regex => '^(NW|Northwest|14)$',
  1179. value_num => 315.0,
  1180. },
  1181. {
  1182. ge => 337.5,
  1183. lt => 360,
  1184. regex => '^(NNW|North-Northwest|15)$',
  1185. value_num => 337.5,
  1186. },
  1187. ],
  1188. },
  1189. rtype_description => {
  1190. de => 'Himmelsrichtung',
  1191. en => 'point of the compass',
  1192. },
  1193. tmpl_long => '%txt_long%',
  1194. },
  1195. closure => {
  1196. ref_base => 900,
  1197. txt => {
  1198. de => [ 'geschlossen', 'offen', 'gekippt' ],
  1199. en => [ 'closed', 'open', 'tilted' ],
  1200. },
  1201. scope => [ '^(closed|0)$', '^(open|1)$', '^(tilted|2)$' ],
  1202. rtype_description => {
  1203. de => 'Status für Fenster und Türen',
  1204. en => 'state for windows and doors',
  1205. },
  1206. },
  1207. condition_weather => {
  1208. ref_base => 900,
  1209. txt => {
  1210. de => [ 'klar', 'sonnig', 'bewölkt', 'Regen' ],
  1211. en => [ 'clear', 'sunny', 'cloudy', 'rain' ],
  1212. },
  1213. scope => [
  1214. '^((nt_)?clear|nt_sunny|0)$', '^(sunny|1)$',
  1215. '^((nt_)?cloudy|2)$', '^((nt_)?rain|3)$'
  1216. ],
  1217. rtype_description => {
  1218. de => 'Wetterbedingung',
  1219. en => 'weather condition',
  1220. },
  1221. },
  1222. condition_hum => {
  1223. ref_base => 900,
  1224. txt => {
  1225. de => [ 'trocken', 'niedrig', 'optimal', 'hoch', 'feucht' ],
  1226. en => [ 'dry', 'low', 'optimal', 'high', 'wet' ],
  1227. },
  1228. scope => [
  1229. '^(dry|0)$', '^(low|1)$', '^(optimal|2)$', '^(high|3)$',
  1230. '^(wet|4)$'
  1231. ],
  1232. rtype_description => {
  1233. de => 'Feuchtigkeitsbedingung',
  1234. en => 'humidity condition',
  1235. },
  1236. },
  1237. condition_uvi => {
  1238. ref_base => 900,
  1239. txt => {
  1240. de => [ 'niedrig', 'moderat', 'hoch', 'sehr hoch', 'extrem' ],
  1241. en => [ 'low', 'moderate', 'high', 'very high', 'extreme' ],
  1242. },
  1243. scope => [
  1244. '^(low|0)$', '^(moderate|1)$',
  1245. '^(high|2)$', '^(veryhigh|3)$',
  1246. '^(extreme|4)$'
  1247. ],
  1248. rtype_description => {
  1249. de => 'UV Bedingung',
  1250. en => 'UV condition',
  1251. },
  1252. },
  1253. # logical operators
  1254. bool => {
  1255. ref_base => 26,
  1256. txt => {
  1257. de => [ 'falsch', 'wahr' ],
  1258. en => [ 'false', 'true' ],
  1259. },
  1260. scope => [ '^(false|no|0)$', '^(true|yes|1)$' ],
  1261. rtype_description => {
  1262. de => 'Boolesch wahr/falsch',
  1263. en => 'Boolean true/false',
  1264. },
  1265. },
  1266. yesno => {
  1267. ref_base => 26,
  1268. txt => {
  1269. de => [ 'nein', 'ja' ],
  1270. en => [ 'no', 'yes' ],
  1271. },
  1272. scope => [ '^(no|n|false|0)$', '^(yes|y|true|1)$' ],
  1273. rtype_description => {
  1274. de => 'Boolesch ja/nein',
  1275. en => 'Boolean ja/nein',
  1276. },
  1277. },
  1278. # numbering
  1279. short => {
  1280. ref_base => 25,
  1281. format => '%i',
  1282. rtype_description => {
  1283. de => 'Ganzzahl zwischen -32768 und 32767',
  1284. en => 'Integer between -32768 and 32767',
  1285. },
  1286. scope => { minValue => -32768, maxValue => 32767 },
  1287. },
  1288. rshort => {
  1289. ref_base => 25,
  1290. format => '%.0f',
  1291. rtype_description => {
  1292. de => 'gerundete Ganzzahl zwischen -32768 und 32767',
  1293. en => 'rounded integer between -32768 and 32767',
  1294. },
  1295. scope => { minValue => -32768, maxValue => 32767 },
  1296. },
  1297. long => {
  1298. ref_base => 25,
  1299. format => '%i',
  1300. rtype_description => {
  1301. de => 'Ganzzahl zwischen -2147483648 und 214748364',
  1302. en => 'Integer between -2147483648 and 214748364',
  1303. },
  1304. scope => { minValue => -2147483648, maxValue => 214748364 },
  1305. },
  1306. rlong => {
  1307. ref_base => 25,
  1308. format => '%.0f',
  1309. rtype_description => {
  1310. de => 'gerundete Ganzzahl zwischen -2147483648 und 214748364',
  1311. en => 'rounded integer between -2147483648 and 214748364',
  1312. },
  1313. scope => { minValue => -2147483648, maxValue => 214748364 },
  1314. },
  1315. integer => {
  1316. ref_base => 25,
  1317. format => '%i',
  1318. rtype_description => {
  1319. de => 'Ganzzahl',
  1320. en => 'Integer',
  1321. },
  1322. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1323. },
  1324. rinteger => {
  1325. ref_base => 25,
  1326. format => '%.0f',
  1327. rtype_description => {
  1328. de => 'gerundete Ganzzahl',
  1329. en => 'rounded integer',
  1330. },
  1331. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1332. },
  1333. float => {
  1334. ref_base => 25,
  1335. format => '%.2f',
  1336. rtype_description => {
  1337. de => 'Fließkommazahl',
  1338. en => 'floating number',
  1339. },
  1340. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1341. },
  1342. pct => {
  1343. ref_base => 25,
  1344. format => '%i',
  1345. symbol => chr(0x0025),
  1346. suffix => 'pct',
  1347. tmpl => '%value%' . chr(0x202F) . '%symbol%',
  1348. tmpl_long => '%value% %txt%',
  1349. txt => {
  1350. de => 'Prozent',
  1351. en => 'percent',
  1352. },
  1353. scope => { minValue => 0, maxValue => 100 },
  1354. },
  1355. # currency
  1356. #https://en.wikipedia.org/wiki/Euro
  1357. #https://en.wikipedia.org/wiki/Linguistic_issues_concerning_the_euro
  1358. euro => {
  1359. ref_base => 24,
  1360. format => '%.2f',
  1361. symbol => '€',
  1362. suffix => 'EUR',
  1363. txt => {
  1364. de => 'Euro',
  1365. en => 'euro',
  1366. },
  1367. tmpl => {
  1368. de => '%symbol%%value%',
  1369. de_de => '%value%' . chr(0x202F) . '%symbol%',
  1370. en => '%symbol%%value%',
  1371. },
  1372. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1373. },
  1374. pound_uk => {
  1375. ref_base => 24,
  1376. format => '%.2f',
  1377. symbol => '£',
  1378. suffix => 'GBP',
  1379. txt => {
  1380. de => 'Pfund',
  1381. en => 'pound',
  1382. },
  1383. txt_long => {
  1384. de => 'Britisches Pfund',
  1385. en => 'British pound',
  1386. },
  1387. txt_long_pl => {
  1388. de => 'Britische Pfund',
  1389. en => 'British pound',
  1390. },
  1391. tmpl => '%symbol%%value%',
  1392. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1393. },
  1394. dollar_us => {
  1395. ref_base => 24,
  1396. format => '%.2f',
  1397. symbol => '$',
  1398. suffix => 'USD',
  1399. txt => {
  1400. de => 'Dollar',
  1401. en => 'dollar',
  1402. },
  1403. txt_long => {
  1404. de => 'US Dollar',
  1405. en => 'US dollar',
  1406. },
  1407. tmpl => '%symbol%%value%',
  1408. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1409. },
  1410. cent => {
  1411. ref_base => 24,
  1412. format => '%.0f',
  1413. symbol => {
  1414. de => 'ct',
  1415. en => '¢',
  1416. },
  1417. suffix => {
  1418. de => 'ct',
  1419. en => 'c',
  1420. },
  1421. txt => {
  1422. de => 'Cent',
  1423. en => 'cent',
  1424. },
  1425. tmpl => {
  1426. de => '%value%%symbol%',
  1427. de_de => '%value%' . chr(0x202F) . '%symbol%',
  1428. en => '%value%%symbol%',
  1429. },
  1430. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1431. },
  1432. # plane angular
  1433. gon => {
  1434. ref_base => 14,
  1435. symbol => chr(0x00B0),
  1436. suffix => 'gon',
  1437. txt => {
  1438. de => 'Grad',
  1439. en => 'gradians',
  1440. },
  1441. tmpl => '%value%%symbol%',
  1442. decimal_mark => {
  1443. de => 2,
  1444. en => 1,
  1445. },
  1446. format => '%i',
  1447. },
  1448. rad => {
  1449. ref_base => 14,
  1450. suffix => 'rad',
  1451. txt => {
  1452. de => 'Radiant',
  1453. en => 'radiant',
  1454. },
  1455. decimal_mark => {
  1456. de => 2,
  1457. en => 1,
  1458. },
  1459. format => '%i',
  1460. },
  1461. # temperature
  1462. c => {
  1463. ref_base => 4,
  1464. symbol => chr(0x00B0) . 'C',
  1465. suffix => 'C',
  1466. txt => {
  1467. de => 'Grad Celsius',
  1468. en => 'Degree Celsius',
  1469. },
  1470. txt_pl => {
  1471. de => 'Grad Celsius',
  1472. en => 'Degrees Celsius',
  1473. },
  1474. scope => { minValue => -273.15 },
  1475. },
  1476. f => {
  1477. ref_base => 4,
  1478. symbol => chr(0x00B0) . 'F',
  1479. suffix => 'F',
  1480. txt => {
  1481. de => 'Grad Fahrenheit',
  1482. en => 'Degree Fahrenheit',
  1483. },
  1484. txt_pl => {
  1485. de => 'Grad Fahrenheit',
  1486. en => 'Degrees Fahrenheit',
  1487. },
  1488. scope => { minValue => -459.67 },
  1489. },
  1490. k => {
  1491. ref_base => 4,
  1492. suffix => 'K',
  1493. txt => {
  1494. de => 'Kelvin',
  1495. en => 'Kelvin',
  1496. },
  1497. },
  1498. # pressure
  1499. bar => {
  1500. ref_base => 10,
  1501. scale_m => '1.0e0',
  1502. suffix => 'bar',
  1503. txt => {
  1504. de => 'Bar',
  1505. en => 'Bar',
  1506. },
  1507. },
  1508. mbar => {
  1509. ref => 'bar',
  1510. scale_m => '1.0e-3',
  1511. },
  1512. pa => {
  1513. ref_base => 10,
  1514. scale_m => '1.0e0',
  1515. suffix => 'Pa',
  1516. txt => {
  1517. de => 'Pascal',
  1518. en => 'Pascal',
  1519. },
  1520. },
  1521. hpa => {
  1522. ref => 'pa',
  1523. scale_m => '1.0e2',
  1524. },
  1525. pamb => {
  1526. ref_base => 12,
  1527. scale_m => '1.0e0',
  1528. suffix => 'Pa',
  1529. txt => {
  1530. de => 'Pascal',
  1531. en => 'Pascal',
  1532. },
  1533. },
  1534. hpamb => {
  1535. ref => 'pamb',
  1536. scale_m => '1.0e2',
  1537. },
  1538. inhg => {
  1539. ref_base => 12,
  1540. suffix => 'inHg',
  1541. txt => {
  1542. de => 'Zoll Quecksilbersäule',
  1543. en => 'Inches of Mercury',
  1544. },
  1545. },
  1546. mmhg => {
  1547. ref_base => 12,
  1548. suffix => 'mmHg',
  1549. txt => {
  1550. de => 'Millimeter Quecksilbersäule',
  1551. en => 'Milimeter of Mercury',
  1552. },
  1553. },
  1554. # length
  1555. km => {
  1556. ref => 'm',
  1557. scale_m => '1.0e3',
  1558. },
  1559. hm => {
  1560. ref => 'm',
  1561. scale_m => '1.0e2',
  1562. },
  1563. dam => {
  1564. ref => 'm',
  1565. scale_m => '1.0e1',
  1566. },
  1567. m => {
  1568. ref_base => 0,
  1569. scale_m => '1.0e0',
  1570. suffix => 'm',
  1571. txt => {
  1572. de => 'Meter',
  1573. en => 'meter',
  1574. },
  1575. },
  1576. dm => {
  1577. ref => 'm',
  1578. scale_m => '1.0e-1',
  1579. },
  1580. cm => {
  1581. ref => 'm',
  1582. scale_m => '1.0e-2',
  1583. },
  1584. mm => {
  1585. ref => 'm',
  1586. scale_m => '1.0e-3',
  1587. },
  1588. um => {
  1589. ref => 'm',
  1590. scale_m => '1.0e-6',
  1591. },
  1592. nm => {
  1593. ref => 'm',
  1594. scale_m => '1.0e-9',
  1595. },
  1596. pm => {
  1597. ref => 'm',
  1598. scale_m => '1.0e-12',
  1599. },
  1600. fm => {
  1601. ref => 'm',
  1602. scale_m => '1.0e-15',
  1603. },
  1604. in => {
  1605. ref_base => 0,
  1606. symbol => '″',
  1607. suffix => 'in',
  1608. txt => {
  1609. de => 'Zoll',
  1610. en => 'inch',
  1611. },
  1612. txt_pl => {
  1613. de => 'Zoll',
  1614. en => 'inches',
  1615. },
  1616. tmpl => '%value%%symbol%',
  1617. },
  1618. ft => {
  1619. ref_base => 0,
  1620. symbol => '′',
  1621. suffix => 'ft',
  1622. txt => {
  1623. de => 'Fuss',
  1624. en => 'foot',
  1625. },
  1626. txt_pl => {
  1627. de => 'Fuss',
  1628. en => 'feet',
  1629. },
  1630. tmpl => '%value%%symbol%',
  1631. },
  1632. yd => {
  1633. ref_base => 0,
  1634. suffix => 'yd',
  1635. txt => {
  1636. de => 'Yard',
  1637. en => 'yard',
  1638. },
  1639. txt_pl => {
  1640. de => 'Yards',
  1641. en => 'yards',
  1642. },
  1643. },
  1644. mi => {
  1645. ref_base => 0,
  1646. suffix => 'mi',
  1647. txt => {
  1648. de => 'Meilen',
  1649. en => 'miles',
  1650. },
  1651. },
  1652. # time
  1653. sec => {
  1654. ref_base => 2,
  1655. scale_t => 's',
  1656. suffix => {
  1657. de => 's',
  1658. en => 's',
  1659. },
  1660. txt => {
  1661. de => 'Sekunde',
  1662. en => 'second',
  1663. },
  1664. txt_pl => {
  1665. de => 'Sekunden',
  1666. en => 'seconds',
  1667. },
  1668. },
  1669. min => {
  1670. ref_base => 2,
  1671. scale_t => 'min',
  1672. suffix => {
  1673. de => 'Min',
  1674. en => 'min',
  1675. },
  1676. txt => {
  1677. de => 'Minute',
  1678. en => 'minute',
  1679. },
  1680. txt_pl => {
  1681. de => 'Minuten',
  1682. en => 'minutes',
  1683. },
  1684. },
  1685. hr => {
  1686. ref_base => 2,
  1687. scale_t => 'h',
  1688. suffix => 'h',
  1689. txt => {
  1690. de => 'Stunde',
  1691. en => 'hour',
  1692. },
  1693. txt_pl => {
  1694. de => 'Stunden',
  1695. en => 'hours',
  1696. },
  1697. },
  1698. d => {
  1699. ref_base => 2,
  1700. scale_t => 'd',
  1701. suffix => {
  1702. de => 'T',
  1703. en => 'd',
  1704. },
  1705. txt => {
  1706. de => 'Tag',
  1707. en => 'day',
  1708. },
  1709. txt_pl => {
  1710. de => 'Tage',
  1711. en => 'days',
  1712. },
  1713. },
  1714. w => {
  1715. ref_base => 2,
  1716. scale_t => 'w',
  1717. suffix => {
  1718. de => 'W',
  1719. en => 'w',
  1720. },
  1721. txt => {
  1722. de => 'Woche',
  1723. en => 'week',
  1724. },
  1725. txt_pl => {
  1726. de => 'Wochen',
  1727. en => 'weeks',
  1728. },
  1729. },
  1730. mon => {
  1731. ref_base => 2,
  1732. scale_t => 'm',
  1733. suffix => {
  1734. de => 'M',
  1735. en => 'm',
  1736. },
  1737. txt => {
  1738. de => 'Monat',
  1739. en => 'month',
  1740. },
  1741. txt_pl => {
  1742. de => 'Monate',
  1743. en => 'Monat',
  1744. },
  1745. },
  1746. y => {
  1747. ref_base => 2,
  1748. scale_t => 'a',
  1749. suffix => {
  1750. de => 'J',
  1751. en => 'y',
  1752. },
  1753. txt => {
  1754. de => 'Jahr',
  1755. en => 'year',
  1756. },
  1757. txt_pl => {
  1758. de => 'Jahre',
  1759. en => 'years',
  1760. },
  1761. },
  1762. epoch => {
  1763. ref_base => 2,
  1764. scale_t => 's',
  1765. scope => { minValue => 0 },
  1766. rtype_description => {
  1767. de => 'Unix Epoche in s seit 1970-01-01T00:00:00Z',
  1768. en => 'Unix epoch in s since 1970-01-01T00:00:00Z',
  1769. },
  1770. },
  1771. time => {
  1772. ref_base => 2,
  1773. scope => '^(([0-1]?[0-9]|[0-2]?[0-3]):([0-5]?[0-9]))$',
  1774. rtype_description => {
  1775. de => 'Uhrzeit hh:mm',
  1776. en => 'time hh:mm',
  1777. },
  1778. tmpl_long => {
  1779. de => '%value%' . chr(0x00A0) . 'Uhr',
  1780. en => '%value%',
  1781. }
  1782. },
  1783. datetime => {
  1784. ref_base => 2,
  1785. scope =>
  1786. '^(([1-2][0-9]{3})-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|30|31) (0?[1-9]|1[0-9]|2[0-3]):(0?[1-9]|[1-5][0-9]))$',
  1787. rtype_description => {
  1788. de => 'Datum+Uhrzeit YYYY-mm-dd hh:mm',
  1789. en => 'date+time YYYY-mm-dd hh:mm',
  1790. },
  1791. },
  1792. timesec => {
  1793. ref_base => 900,
  1794. scope => '^(([0-1]?[0-9]|[0-2]?[0-3]):([0-5]?[0-9]):([0-5]?[0-9]))$',
  1795. rtype_description => {
  1796. de => 'Uhrzeit hh:mm:ss',
  1797. en => 'time hh:mm:ss',
  1798. },
  1799. },
  1800. datetimesec => {
  1801. ref_base => 2,
  1802. scope =>
  1803. '^(([1-2][0-9]{3})-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|30|31) (0?[1-9]|1[0-9]|2[0-3]):(0?[1-9]|[1-5][0-9]):(0?[1-9]|[1-5][0-9]))$',
  1804. rtype_description => {
  1805. de => 'Datum+Uhrzeit YYYY-mm-dd hh:mm:ss',
  1806. en => 'date+time YYYY-mm-dd hh:mm:ss',
  1807. },
  1808. },
  1809. # speed
  1810. bft => {
  1811. ref_base => 15,
  1812. suffix => 'bft',
  1813. txt => {
  1814. de => 'Windstärke',
  1815. en => 'wind force',
  1816. },
  1817. tmpl_long => '%txt% %value%',
  1818. },
  1819. kn => {
  1820. ref_base => 15,
  1821. suffix => 'kn',
  1822. txt => {
  1823. de => 'Knoten',
  1824. en => 'knots',
  1825. },
  1826. },
  1827. fts => {
  1828. ref_base => 15,
  1829. ref => 'ft',
  1830. ref_t => 'sec',
  1831. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_t%',
  1832. tmpl_long => {
  1833. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_t%',
  1834. en => '%value%' . chr(0x00A0) . '%txt% per %txt_t%',
  1835. },
  1836. tmpl_long_pl => {
  1837. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_t%',
  1838. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_t%',
  1839. },
  1840. },
  1841. mph => {
  1842. ref_base => 15,
  1843. ref => 'mi',
  1844. ref_t => 'hr',
  1845. tmpl => '%value%' . chr(0x00A0) . 'mph',
  1846. tmpl_long => {
  1847. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_t%',
  1848. en => '%value%' . chr(0x00A0) . '%txt% per %txt_t%',
  1849. },
  1850. tmpl_long_pl => {
  1851. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_t%',
  1852. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_t%',
  1853. },
  1854. },
  1855. kmph => {
  1856. ref_base => 15,
  1857. ref => 'm',
  1858. ref_t => 'hr',
  1859. scale_m => '1.0e3',
  1860. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_t%',
  1861. tmpl_long => {
  1862. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_t%',
  1863. en => '%value%' . chr(0x00A0) . '%txt% per %txt_t%',
  1864. },
  1865. tmpl_long_pl => {
  1866. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_t%',
  1867. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_t%',
  1868. },
  1869. },
  1870. mps => {
  1871. ref_base => 15,
  1872. ref => 'm',
  1873. ref_t => 'sec',
  1874. scale_m => '1.0e0',
  1875. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_t%',
  1876. tmpl_long => {
  1877. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_t%',
  1878. en => '%value%' . chr(0x00A0) . '%txt% per %txt_t%',
  1879. },
  1880. tmpl_long_pl => {
  1881. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_t%',
  1882. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_t%',
  1883. },
  1884. },
  1885. # weight
  1886. mol => {
  1887. ref_base => 5,
  1888. suffix => 'mol',
  1889. },
  1890. pg => {
  1891. ref => 'g',
  1892. scale_m => "1.0e-12",
  1893. },
  1894. ng => {
  1895. ref => 'g',
  1896. scale_m => "1.0e-9",
  1897. },
  1898. ug => {
  1899. ref => 'g',
  1900. scale_m => "1.0e-6",
  1901. },
  1902. mg => {
  1903. ref => 'g',
  1904. scale_m => "1.0e-3",
  1905. },
  1906. cg => {
  1907. ref => 'g',
  1908. scale_m => "1.0e-2",
  1909. },
  1910. dg => {
  1911. ref => 'g',
  1912. scale_m => "1.0e-1",
  1913. },
  1914. g => {
  1915. ref_base => 1,
  1916. scale_m => "1.0e0",
  1917. suffix => 'g',
  1918. txt => {
  1919. de => 'Gramm',
  1920. en => 'gram',
  1921. },
  1922. },
  1923. kg => {
  1924. ref => 'g',
  1925. scale_m => "1.0e3",
  1926. },
  1927. t => {
  1928. ref => 'g',
  1929. scale_m => "1.0e6",
  1930. suffix => 't',
  1931. txt => {
  1932. de => 'Tonne',
  1933. en => 'ton',
  1934. },
  1935. txt_pl => {
  1936. de => 'Tonnen',
  1937. en => 'tons',
  1938. },
  1939. },
  1940. lb => {
  1941. ref_base => 1,
  1942. suffix => 'lb',
  1943. txt => {
  1944. de => 'Pfund',
  1945. en => 'pound',
  1946. },
  1947. },
  1948. lbs => {
  1949. ref_base => 1,
  1950. suffix => 'lbs',
  1951. txt => {
  1952. de => 'Pfund',
  1953. en => 'pound',
  1954. },
  1955. },
  1956. # luminous intensity
  1957. cd => {
  1958. ref_base => 6,
  1959. suffix => 'cd',
  1960. txt => {
  1961. de => 'Candela',
  1962. en => 'Candela',
  1963. },
  1964. },
  1965. # illumination intensity
  1966. lx => {
  1967. ref_base => 16,
  1968. suffix => 'lx',
  1969. txt => {
  1970. de => 'Lux',
  1971. en => 'Lux',
  1972. },
  1973. },
  1974. # luminous flux
  1975. lm => {
  1976. ref_base => 17,
  1977. suffix => 'lm',
  1978. txt => {
  1979. de => 'Lumen',
  1980. en => 'Lumen',
  1981. },
  1982. },
  1983. uvi => {
  1984. ref_base => 900,
  1985. suffix => 'UVI',
  1986. txt => {
  1987. de => 'UV-Index',
  1988. en => 'UV-Index',
  1989. },
  1990. tmpl => '%suffix%' . chr(0x00A0) . '%value%',
  1991. tmpl_long => '%txt%' . chr(0x00A0) . '%value%',
  1992. format => '%i',
  1993. },
  1994. # surface area
  1995. cm2 => {
  1996. ref_base => 23,
  1997. ref => 'm',
  1998. scale_m => '1.0e-2',
  1999. scale_sq => 1,
  2000. },
  2001. m2 => {
  2002. ref_base => 23,
  2003. ref => 'm',
  2004. scale_m => '1.0e0',
  2005. scale_sq => 1,
  2006. },
  2007. # volume
  2008. cm3 => {
  2009. ref_base => 18,
  2010. ref => 'm',
  2011. scale_m => '1.0e-2',
  2012. scale_cu => 1,
  2013. },
  2014. m3 => {
  2015. ref_base => 18,
  2016. ref => 'm',
  2017. scale_m => '1.0e0',
  2018. scale_cu => 1,
  2019. },
  2020. ml => {
  2021. ref => 'l',
  2022. scale_m => '1.0e-3',
  2023. },
  2024. l => {
  2025. ref_base => 18,
  2026. suffix => 'l',
  2027. txt => {
  2028. de => 'Liter',
  2029. en => 'liter',
  2030. },
  2031. txt_pl => {
  2032. de => 'Liter',
  2033. en => 'liters',
  2034. },
  2035. },
  2036. hl => {
  2037. ref => 'l',
  2038. scale_m => '1.0e2',
  2039. },
  2040. b => {
  2041. ref_base => 19,
  2042. scale_m => '1.0e0',
  2043. suffix => 'B',
  2044. txt => {
  2045. de => 'Bel',
  2046. en => 'Bel',
  2047. },
  2048. },
  2049. db => {
  2050. ref => 'b',
  2051. scale_m => '1.0e-1',
  2052. },
  2053. ua => {
  2054. ref => 'a',
  2055. scale_m => '1.0e-6',
  2056. },
  2057. ma => {
  2058. ref => 'a',
  2059. scale_m => '1.0e-3',
  2060. },
  2061. a => {
  2062. ref_base => 3,
  2063. scale_m => '1.0e0',
  2064. suffix => 'A',
  2065. txt => {
  2066. de => 'Ampere',
  2067. en => 'Ampere',
  2068. },
  2069. },
  2070. uv => {
  2071. ref => 'v',
  2072. scale_m => '1.0e-6',
  2073. },
  2074. mv => {
  2075. ref => 'v',
  2076. scale_m => '1.0e-3',
  2077. },
  2078. v => {
  2079. ref_base => 13,
  2080. scale_m => '1.0e0',
  2081. suffix => 'V',
  2082. txt => {
  2083. de => 'Volt',
  2084. en => 'Volt',
  2085. },
  2086. },
  2087. uj => {
  2088. ref => 'j',
  2089. scale_m => '1.0e-6',
  2090. },
  2091. mj => {
  2092. ref => 'j',
  2093. scale_m => '1.0e-3',
  2094. },
  2095. j => {
  2096. ref_base => 7,
  2097. scale_m => '1.0e0',
  2098. suffix => 'J',
  2099. txt => {
  2100. de => 'Joule',
  2101. en => 'Joule',
  2102. },
  2103. },
  2104. uw => {
  2105. ref => 'w',
  2106. scale_m => '1.0e-6',
  2107. },
  2108. mw => {
  2109. ref => 'w',
  2110. scale_m => '1.0e-3',
  2111. },
  2112. w => {
  2113. ref_base => 9,
  2114. scale_m => '1.0e0',
  2115. suffix => 'W',
  2116. txt => {
  2117. de => 'Watt',
  2118. en => 'Watt',
  2119. },
  2120. },
  2121. va => {
  2122. ref => 'w',
  2123. },
  2124. kw => {
  2125. ref => 'w',
  2126. scale_m => '1.0e3',
  2127. },
  2128. megaw => {
  2129. ref => 'w',
  2130. scale_m => '1.0e6',
  2131. },
  2132. whr => {
  2133. base_ref => 7,
  2134. ref => 'w',
  2135. scale_m => '1.0e0',
  2136. ref_t => 'hr',
  2137. scale_t => 'h',
  2138. format => '%.0f',
  2139. tmpl => '%value%' . chr(0x00A0) . '%suffix%',
  2140. tmpl_long => {
  2141. de => '%value%' . chr(0x00A0) . '%txt%',
  2142. en => '%value%' . chr(0x00A0) . '%txt%',
  2143. },
  2144. tmpl_long_pl => {
  2145. de => '%value%' . chr(0x00A0) . '%txt_pl%',
  2146. en => '%value%' . chr(0x00A0) . '%txt_pl%',
  2147. },
  2148. rtype_description => {
  2149. de => 'Wattstunde',
  2150. en => 'Watt hour',
  2151. }
  2152. },
  2153. kwhr => {
  2154. base_ref => 7,
  2155. ref => 'w',
  2156. scale_m => '1.0e3',
  2157. ref_t => 'hr',
  2158. scale_t => 'h',
  2159. format => '%.0f',
  2160. tmpl => '%value%' . chr(0x00A0) . '%suffix%',
  2161. tmpl_long => {
  2162. de => '%value%' . chr(0x00A0) . '%txt%',
  2163. en => '%value%' . chr(0x00A0) . '%txt%',
  2164. },
  2165. tmpl_long_pl => {
  2166. de => '%value%' . chr(0x00A0) . '%txt_pl%',
  2167. en => '%value%' . chr(0x00A0) . '%txt_pl%',
  2168. },
  2169. rtype_description => {
  2170. de => 'Kilowattstunde',
  2171. en => 'Kilowatt hour',
  2172. }
  2173. },
  2174. mwhr => {
  2175. base_ref => 7,
  2176. ref => 'w',
  2177. scale_m => '1.0e6',
  2178. ref_t => 'hr',
  2179. scale_t => 'h',
  2180. format => '%.0f',
  2181. tmpl => '%value%' . chr(0x00A0) . '%suffix%%suffix_t%',
  2182. tmpl_long => {
  2183. de => '%value%' . chr(0x00A0) . '%txt%%txt_t%',
  2184. en => '%value%' . chr(0x00A0) . '%txt% %txt_t%',
  2185. },
  2186. tmpl_long_pl => {
  2187. de => '%value%' . chr(0x00A0) . '%txt%%txt_pl%',
  2188. en => '%value%' . chr(0x00A0) . '%txt% %txt_pl%',
  2189. },
  2190. rtype_description => {
  2191. de => 'Megawattstunde',
  2192. en => 'Megawatt hour',
  2193. }
  2194. },
  2195. gwhr => {
  2196. base_ref => 7,
  2197. ref => 'w',
  2198. scale_m => '1.0e9',
  2199. ref_t => 'hr',
  2200. scale_t => 'h',
  2201. format => '%.0f',
  2202. tmpl => '%value%' . chr(0x00A0) . '%suffix%%suffix_t%',
  2203. tmpl_long => {
  2204. de => '%value%' . chr(0x00A0) . '%txt%%txt_t%',
  2205. en => '%value%' . chr(0x00A0) . '%txt% %txt_t%',
  2206. },
  2207. tmpl_long_pl => {
  2208. de => '%value%' . chr(0x00A0) . '%txt%%txt_pl%',
  2209. en => '%value%' . chr(0x00A0) . '%txt% %txt_pl%',
  2210. },
  2211. rtype_description => {
  2212. de => 'Gigawattstunde',
  2213. en => 'Gigawatt hour',
  2214. }
  2215. },
  2216. uwpscm => {
  2217. ref => 'w',
  2218. scale_m => '1.0e-6',
  2219. ref_sq => 'm',
  2220. scale_sq => '1.0e-2',
  2221. format => '%.0f',
  2222. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2223. tmpl_long => {
  2224. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2225. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2226. },
  2227. tmpl_long_pl => {
  2228. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2229. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2230. },
  2231. },
  2232. uwpsm => {
  2233. ref => 'w',
  2234. scale_m => '1.0e-6',
  2235. ref_sq => 'm',
  2236. scale_sq => '1.0e0',
  2237. format => '%.0f',
  2238. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2239. tmpl_long => {
  2240. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2241. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2242. },
  2243. tmpl_long_pl => {
  2244. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2245. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2246. },
  2247. },
  2248. mwpscm => {
  2249. ref => 'w',
  2250. scale_m => '1.0e-3',
  2251. ref_sq => 'm',
  2252. scale_sq => '1.0e-2',
  2253. format => '%.0f',
  2254. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2255. tmpl_long => {
  2256. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2257. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2258. },
  2259. tmpl_long_pl => {
  2260. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2261. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2262. },
  2263. },
  2264. mwpsm => {
  2265. ref => 'w',
  2266. scale_m => '1.0e-3',
  2267. ref_sq => 'm',
  2268. scale_sq => '1.0e0',
  2269. format => '%.0f',
  2270. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2271. tmpl_long => {
  2272. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2273. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2274. },
  2275. tmpl_long_pl => {
  2276. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2277. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2278. },
  2279. },
  2280. wpscm => {
  2281. ref => 'w',
  2282. scale_m => '1.0e0',
  2283. ref_sq => 'm',
  2284. scale_sq => '1.0e-2',
  2285. format => '%.0f',
  2286. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2287. tmpl_long => {
  2288. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2289. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2290. },
  2291. tmpl_long_pl => {
  2292. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2293. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2294. },
  2295. },
  2296. wpsm => {
  2297. ref => 'w',
  2298. scale_m => '1.0e0',
  2299. ref_sq => 'm',
  2300. scale_sq => '1.0e0',
  2301. format => '%.0f',
  2302. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2303. tmpl_long => {
  2304. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2305. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2306. },
  2307. tmpl_long_pl => {
  2308. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2309. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2310. },
  2311. },
  2312. coul => {
  2313. ref_base => 20,
  2314. suffix => 'C',
  2315. txt => {
  2316. de => 'Coulomb',
  2317. en => 'Coulomb',
  2318. },
  2319. },
  2320. far => {
  2321. ref_base => 21,
  2322. suffix => 'F',
  2323. txt => {
  2324. de => 'Farad',
  2325. en => 'Farad',
  2326. },
  2327. },
  2328. ohm => {
  2329. ref_base => 22,
  2330. symbol => 'Ω',
  2331. suffix => 'Ohm',
  2332. txt => {
  2333. de => 'Ohm',
  2334. en => 'Ohm',
  2335. },
  2336. },
  2337. };
  2338. # helps the user to assign rtypes to existing readings of modules
  2339. # w/o built-in rtype support
  2340. #
  2341. # layer 1 = module name (exception: global is valid for all modules but
  2342. # with lower preference)
  2343. # layer 2 = reading name as used by that module
  2344. # layer 3 = template for this reading to be copied to device attribute readingsDesc.
  2345. # aliasname makes a reference to another reading name to avoid duplicates
  2346. # and take the opportunity to harmonise reading names here.
  2347. my $readingsDB = {
  2348. global => {
  2349. airpress => {
  2350. aliasname => 'pressure_hpa', # alias only
  2351. },
  2352. azimuth => {
  2353. rtype => 'gon',
  2354. },
  2355. compasspoint => {
  2356. rtype => 'compasspoint'
  2357. },
  2358. daylight => {
  2359. rtype => 'yesno',
  2360. },
  2361. dewpoint => {
  2362. aliasname => 'dewpoint_c', # alias only
  2363. },
  2364. dewpoint_c => {
  2365. rtype => 'c',
  2366. },
  2367. elevation => {
  2368. rtype => 'gon',
  2369. },
  2370. feelslike => {
  2371. aliasname => 'feelslike_c', # alias only
  2372. },
  2373. feelslike_c => {
  2374. rtype => 'c',
  2375. },
  2376. humidity => {
  2377. rtype => 'pct',
  2378. formula_symbol => 'H',
  2379. },
  2380. humidityabs => {
  2381. aliasname => 'humidityabs_c', # alias only
  2382. },
  2383. humidityabs_c => {
  2384. rtype => 'c',
  2385. formula_symbol => 'H',
  2386. },
  2387. humidityabs_f => {
  2388. rtype => 'f',
  2389. formula_symbol => 'H',
  2390. },
  2391. humidityabs_k => {
  2392. rtype => 'k',
  2393. formula_symbol => 'H',
  2394. },
  2395. horizon => {
  2396. rtype => 'gon',
  2397. },
  2398. indoordewpoint => {
  2399. aliasname => 'indoordewpoint_c', # alias only
  2400. },
  2401. indoordewpoint_c => {
  2402. rtype => 'c',
  2403. },
  2404. indoorhumidity => {
  2405. rtype => 'pct',
  2406. formula_symbol => 'H',
  2407. },
  2408. indoorhumidityabs => {
  2409. aliasname => 'indoorhumidityabs_c', # alias only
  2410. },
  2411. indoorhumidityabs_c => {
  2412. rtype => 'c',
  2413. },
  2414. indoortemperature => {
  2415. aliasname => 'indoortemperature_c', # alias only
  2416. },
  2417. indoortemperature_c => {
  2418. rtype => 'c',
  2419. },
  2420. israining => {
  2421. rtype => 'yesno',
  2422. },
  2423. level => {
  2424. rtype => 'pct',
  2425. },
  2426. luminosity => {
  2427. rtype => 'lx',
  2428. },
  2429. pct => {
  2430. rtype => 'pct',
  2431. },
  2432. pressure => {
  2433. aliasname => 'pressure_hpa', # alias only
  2434. },
  2435. pressure_hpa => {
  2436. rtype => 'hpamb',
  2437. },
  2438. pressure_in => {
  2439. rtype => 'inhg',
  2440. },
  2441. pressure_mm => {
  2442. rtype => 'mmhg',
  2443. },
  2444. pressureabs => {
  2445. aliasname => 'pressureabs_hpamb', # alias only
  2446. },
  2447. pressureabs_hpamb => {
  2448. rtype => 'hpamb',
  2449. },
  2450. pressureabs_in => {
  2451. rtype => 'inhg',
  2452. },
  2453. pressureabs_mm => {
  2454. rtype => 'mmhg',
  2455. },
  2456. pressureabs_psi => {
  2457. aliasname => 'pressureabs_psia',
  2458. },
  2459. pressureabs_psia => {
  2460. rtype => 'psia',
  2461. },
  2462. rain => {
  2463. aliasname => 'rain_mm', # alias only
  2464. },
  2465. rain_mm => {
  2466. rtype => 'mm',
  2467. },
  2468. rain_day => {
  2469. aliasname => 'rain_day_mm', # alias only
  2470. },
  2471. rain_day_mm => {
  2472. rtype => 'mm',
  2473. },
  2474. rain_night => {
  2475. aliasname => 'rain_night_mm', # alias only
  2476. },
  2477. rain_night_mm => {
  2478. rtype => 'mm',
  2479. },
  2480. rain_week => {
  2481. aliasname => 'rain_week_mm', # alias only
  2482. },
  2483. rain_week_mm => {
  2484. rtype => 'mm',
  2485. },
  2486. rain_month => {
  2487. aliasname => 'rain_month_mm', # alias only
  2488. },
  2489. rain_month_mm => {
  2490. rtype => 'mm',
  2491. },
  2492. rain_year => {
  2493. aliasname => 'rain_year_mm', # alias only
  2494. },
  2495. rain_year_mm => {
  2496. rtype => 'mm',
  2497. },
  2498. snow => {
  2499. aliasname => 'snow_cm', # alias only
  2500. },
  2501. snow_cm => {
  2502. rtype => 'cm',
  2503. },
  2504. snow_day => {
  2505. aliasname => 'snow_day_cm', # alias only
  2506. },
  2507. snow_day_cm => {
  2508. rtype => 'cm',
  2509. },
  2510. snow_night => {
  2511. aliasname => 'snow_night_cm', # alias only
  2512. },
  2513. snow_night_cm => {
  2514. rtype => 'cm',
  2515. },
  2516. sunshine => {
  2517. aliasname => 'solarradiation', # alias only
  2518. },
  2519. solarradiation => {
  2520. rtype => 'wpsm',
  2521. },
  2522. temp => {
  2523. aliasname => 'temperature_c', # alias only
  2524. },
  2525. temp_c => {
  2526. aliasname => 'temperature_c', # alias only
  2527. },
  2528. temperature => {
  2529. aliasname => 'temperature_c', # alias only
  2530. },
  2531. temperature_c => {
  2532. rtype => 'c',
  2533. },
  2534. uv => {
  2535. aliasname => 'uvi', # alias only
  2536. },
  2537. uvi => {
  2538. rtype => 'uvi',
  2539. },
  2540. uvr => {
  2541. rtype => 'uwpscm',
  2542. },
  2543. valvedesired => {
  2544. aliasname => 'valve', # alias only
  2545. },
  2546. valvepos => {
  2547. aliasname => 'valve', # alias only
  2548. },
  2549. valveposition => {
  2550. aliasname => 'valve', # alias only
  2551. },
  2552. valvepostc => {
  2553. aliasname => 'valve', # alias only
  2554. },
  2555. valve => {
  2556. rtype => 'pct',
  2557. },
  2558. visibility => {
  2559. aliasname => 'visibility_km', # alias only
  2560. },
  2561. visibility_km => {
  2562. rtype => 'km',
  2563. },
  2564. wind_chill => {
  2565. aliasname => 'wind_chill_c', # alias only
  2566. },
  2567. wind_chill_c => {
  2568. rtype => 'c',
  2569. },
  2570. wind_compasspoint => {
  2571. rtype => 'compasspoint'
  2572. },
  2573. windspeeddirection => {
  2574. aliasname => 'wind_compasspoint', # alias only
  2575. },
  2576. winddirectiontext => {
  2577. aliasname => 'wind_compasspoint', # alias only
  2578. },
  2579. wind_direction => {
  2580. aliasname => 'wind_compasspoint', # alias only
  2581. },
  2582. wind_dir => {
  2583. aliasname => 'wind_compasspoint', # alias only
  2584. },
  2585. winddir => {
  2586. aliasname => 'wind_compasspoint', # alias only
  2587. },
  2588. winddirection => {
  2589. aliasname => 'wind_compasspoint', # alias only
  2590. },
  2591. wind_gust => {
  2592. aliasname => 'wind_gust_kmh', # alias only
  2593. },
  2594. wind_gust_kmh => {
  2595. rtype => 'kmh',
  2596. },
  2597. wind_speed => {
  2598. aliasname => 'wind_speed_kmh', # alias only
  2599. },
  2600. wind_speed_kmh => {
  2601. rtype => 'kmh',
  2602. },
  2603. }
  2604. };
  2605. # Find rtype through reading name
  2606. sub rname2rtype ($$@) {
  2607. my ( $name, $reading, $lang ) = @_;
  2608. my $details;
  2609. my $r = $reading;
  2610. my $l = ( $lang ? lc($lang) : "en" );
  2611. my $rt;
  2612. my $guess;
  2613. my %return;
  2614. # remove some prefix or other values to
  2615. # flatten reading name
  2616. $r =~ s/^fc\d+_//i;
  2617. $r =~ s/_(min|max|avg|sum|cum|avg\d+m|sum\d+m|cum\d+m)_/_/i;
  2618. $r =~ s/^(min|max|avg|sum|cum|avg\d+m|sum\d+m|cum\d+m)_//i;
  2619. $r =~ s/_(min|max|avg|sum|cum|avg\d+m|sum\d+m|cum\d+m)$//i;
  2620. $r =~ s/.*[-_](temp)$/$1/i;
  2621. # rename capital letter containing readings
  2622. if ( !$readingsDB->{global}{ lc($r) } ) {
  2623. $r =~ s/^([A-Z])(.*)/\l$1$2/;
  2624. $r =~ s/([A-Z][a-z0-9]+)[\/\|\-_]?/_$1/g;
  2625. }
  2626. $r = lc($r);
  2627. # known aliasname reading names
  2628. if ( $readingsDB->{global}{$r}{aliasname} ) {
  2629. my $dr = $readingsDB->{global}{$r}{aliasname};
  2630. $return{aliasname} = $dr;
  2631. $return{shortname} = $readingsDB->{global}{$dr}{shortname};
  2632. $rt = (
  2633. $readingsDB->{global}{$dr}{rtype}
  2634. ? $readingsDB->{global}{$dr}{rtype}
  2635. : "-"
  2636. );
  2637. }
  2638. # known standard reading names
  2639. elsif ( $readingsDB->{global}{$r}{shortname} ) {
  2640. $return{aliasname} = $reading;
  2641. $return{shortname} = $readingsDB->{global}{$r}{shortname};
  2642. $rt = (
  2643. $readingsDB->{global}{$r}{rtype}
  2644. ? $readingsDB->{global}{$r}{rtype}
  2645. : "-"
  2646. );
  2647. }
  2648. # just guessing the rtype from reading name format
  2649. elsif ( $r =~ /^.*_([A-Za-z0-9]+)$/i ) {
  2650. $return{guess} = 1;
  2651. $rt = $1;
  2652. }
  2653. return $rt if ( $rt && $rtypes->{$rt} );
  2654. }
  2655. ######################################
  2656. # package main
  2657. #
  2658. package main;
  2659. use utf8;
  2660. # Do the magic to generate value + unit combined text strings
  2661. # for specified language
  2662. sub replaceTemplate ($$$$;$) {
  2663. my ( $device, $reading, $odesc, $lang, $value ) = @_;
  2664. my $l = ( $lang ? lc($lang) : "en" );
  2665. my $txt;
  2666. my $txt_long;
  2667. my $r = $defs{$device}{READINGS} if ($device);
  2668. return
  2669. if ( !$odesc || ref($odesc) ne "HASH" );
  2670. $value = ${$odesc}{value}{$lang}
  2671. if (!defined($value)
  2672. && defined( $odesc->{value} )
  2673. && defined( $odesc->{value}{$lang} ) );
  2674. return $value
  2675. if ( !defined($value) || $value eq "" || !defined( $odesc->{rtype} ) );
  2676. # clone
  2677. my $desc;
  2678. foreach ( keys %{$odesc} ) {
  2679. next
  2680. if ( $_ eq "scope"
  2681. || $_ eq "format"
  2682. || $_ eq "factor"
  2683. || $_ eq "scale" );
  2684. $desc->{$_} = $odesc->{$_};
  2685. }
  2686. ##########
  2687. # language support
  2688. #
  2689. # keep only defined language if set
  2690. foreach ( keys %{$desc} ) {
  2691. next
  2692. if (!defined( $desc->{$_} )
  2693. || ref( $desc->{$_} ) ne "HASH" );
  2694. # find any direct format
  2695. if ( defined( $desc->{$_}{$l} ) ) {
  2696. my $v;
  2697. $v = $desc->{$_}{$l};
  2698. delete $desc->{$_};
  2699. $desc->{$_} = $v if ( defined($v) );
  2700. Unit_Log3( $device, $reading, $odesc, 9,
  2701. "replaceTemplate $device $reading: RAttr $_: value replaced by language specific version ($l)"
  2702. );
  2703. }
  2704. # try base language format instead
  2705. # and extract xx from xx_yz
  2706. elsif ( $l =~ /^([a-z]+)(_([a-z]+))?$/i
  2707. && defined( $desc->{$_}{$1} ) )
  2708. {
  2709. my $v;
  2710. $v = $desc->{$_}{$1};
  2711. delete $desc->{$_};
  2712. $desc->{$_} = $v if ( defined($v) );
  2713. Unit_Log3( $device, $reading, $odesc, 9,
  2714. "replaceTemplate $device $reading: RAttr $_: value replaced by base language specific version ($1)"
  2715. );
  2716. }
  2717. }
  2718. # if original value was a text string and we got value_num out of it,
  2719. # now try to find the right standardized text value from the ARRAY
  2720. my $value_num =
  2721. ref( $desc->{value_num} ) eq "ARRAY"
  2722. ? $desc->{value_num}[0]
  2723. : ( defined( $desc->{value_num} ) ? $desc->{value_num} : undef );
  2724. if ( defined($value_num) ) {
  2725. foreach ( 'suffix', 'symbol', 'txt', 'txt_pl', 'txt_long',
  2726. 'txt_long_pl' )
  2727. {
  2728. if ( ref( $desc->{$_} ) eq "ARRAY"
  2729. && $desc->{$_}[$value_num] )
  2730. {
  2731. my $v = $desc->{$_}[$value_num];
  2732. delete $desc->{$_};
  2733. $desc->{$_} = $v;
  2734. Unit_Log3( $device, $reading, $odesc, 9,
  2735. "replaceTemplate $device $reading: RAttr $_: value replaced based on ARRAY found using value from 'value_num'"
  2736. );
  2737. }
  2738. }
  2739. }
  2740. ##########
  2741. # template support
  2742. #
  2743. # add metric name to suffix and txt
  2744. if ( $desc->{suffix}
  2745. && $desc->{scale_txt_m} )
  2746. {
  2747. Unit_Log3( $device, $reading, $odesc, 9,
  2748. "replaceTemplate $device $reading: RAttr suffix value rewritten by adding value from 'scale_txt_m'"
  2749. );
  2750. $desc->{suffix} = $desc->{scale_txt_m} . $desc->{suffix};
  2751. }
  2752. if ( $desc->{txt}
  2753. && $desc->{scale_txt_long_m} )
  2754. {
  2755. Unit_Log3( $device, $reading, $odesc, 9,
  2756. "replaceTemplate $device $reading: RAttr txt value rewritten by adding value from 'scale_txt_long_m'"
  2757. );
  2758. $desc->{txt} = $desc->{scale_txt_long_m} . lc( $desc->{txt} );
  2759. }
  2760. # add time information to suffix and txt
  2761. if ( $desc->{suffix}
  2762. && $desc->{scale_txt_t} )
  2763. {
  2764. $desc->{suffix} = $desc->{suffix} . $desc->{scale_txt_t};
  2765. Unit_Log3( $device, $reading, $odesc, 9,
  2766. "replaceTemplate $device $reading: RAttr suffix value rewritten by adding value from 'scale_txt_t'"
  2767. );
  2768. }
  2769. if ( $desc->{txt}
  2770. && $desc->{scale_txt_long_pl_t} )
  2771. {
  2772. $desc->{txt_pl} = $desc->{txt} . lc( $desc->{scale_txt_long_pl_t} );
  2773. Unit_Log3( $device, $reading, $odesc, 9,
  2774. "replaceTemplate $device $reading: RAttr txt_pl value rewritten by adding value from 'scale_txt_long_pl_t'"
  2775. );
  2776. }
  2777. if ( $desc->{txt}
  2778. && $desc->{scale_txt_long_t} )
  2779. {
  2780. $desc->{txt} = $desc->{txt} . lc( $desc->{scale_txt_long_t} );
  2781. Unit_Log3( $device, $reading, $odesc, 9,
  2782. "replaceTemplate $device $reading: RAttr txt value rewritten by adding value from 'scale_txt_long_t'"
  2783. );
  2784. }
  2785. # add square information to suffix and txt
  2786. # if no separate suffix_sq and txt_sq was found
  2787. if ( !$desc->{suffix_sq}
  2788. && $desc->{scale_txt_sq} )
  2789. {
  2790. $desc->{suffix} = $desc->{suffix} . $desc->{scale_txt_sq};
  2791. Unit_Log3( $device, $reading, $odesc, 9,
  2792. "replaceTemplate $device $reading: RAttr suffix value rewritten by adding value from 'scale_txt_sq'"
  2793. );
  2794. }
  2795. if ( !$desc->{txt_sq}
  2796. && $desc->{scale_txt_long_sq} )
  2797. {
  2798. $desc->{txt} = $desc->{scale_txt_long_sq} . lc( $desc->{txt} );
  2799. Unit_Log3( $device, $reading, $odesc, 9,
  2800. "replaceTemplate $device $reading: RAttr txt value rewritten by adding value from 'scale_txt_long_sq'"
  2801. );
  2802. }
  2803. # add cubic information to suffix and txt
  2804. # if no separate suffix_cu and txt_cu was found
  2805. if ( !$desc->{suffix_cu}
  2806. && $desc->{scale_txt_cu} )
  2807. {
  2808. $desc->{suffix} = $desc->{suffix} . $desc->{scale_txt_cu};
  2809. Unit_Log3( $device, $reading, $odesc, 9,
  2810. "replaceTemplate $device $reading: RAttr suffix value rewritten by adding value from 'scale_txt_cu'"
  2811. );
  2812. }
  2813. if ( !$desc->{txt_cu}
  2814. && $desc->{scale_txt_long_cu} )
  2815. {
  2816. $desc->{txt} = $desc->{scale_txt_long_cu} . lc( $desc->{txt} );
  2817. Unit_Log3( $device, $reading, $odesc, 9,
  2818. "replaceTemplate $device $reading: RAttr txt value rewritten by adding value from 'scale_txt_long_cu'"
  2819. );
  2820. }
  2821. # add time information to suffix and txt
  2822. # if no separate suffix_t and txt_t was found
  2823. if ( !$desc->{suffix_t}
  2824. && $desc->{scale_txt_t} )
  2825. {
  2826. $desc->{suffix} = $desc->{suffix} . $desc->{scale_txt_t};
  2827. Unit_Log3( $device, $reading, $odesc, 9,
  2828. "replaceTemplate $device $reading: RAttr suffix value rewritten by adding value from 'scale_txt_t'"
  2829. );
  2830. }
  2831. if ( !$desc->{txt_t}
  2832. && $desc->{scale_txt_long_pl_t} )
  2833. {
  2834. $desc->{txt_pl} = $desc->{txt} . lc( $desc->{scale_txt_long_pl_t} );
  2835. Unit_Log3( $device, $reading, $odesc, 9,
  2836. "replaceTemplate $device $reading: RAttr txt_pl value rewritten by adding value from 'scale_txt_long_pl_t'"
  2837. );
  2838. }
  2839. if ( !$desc->{txt_t}
  2840. && $desc->{scale_txt_long_t} )
  2841. {
  2842. $desc->{txt} = $desc->{txt} . lc( $desc->{scale_txt_long_t} );
  2843. Unit_Log3( $device, $reading, $odesc, 9,
  2844. "replaceTemplate $device $reading: RAttr txt value rewritten by adding value from 'scale_txt_long_t'"
  2845. );
  2846. }
  2847. # add metric name to suffix_sq
  2848. if ( $desc->{suffix_sq}
  2849. && $desc->{scale_txt_m_sq}
  2850. && $desc->{suffix_sq} !~ /$desc->{scale_txt_m_sq}/ )
  2851. {
  2852. $desc->{suffix_sq} = $desc->{scale_txt_m_sq} . $desc->{suffix_sq};
  2853. Unit_Log3( $device, $reading, $odesc, 9,
  2854. "replaceTemplate $device $reading: RAttr suffix_sq value rewritten by adding value from 'scale_txt_m_sq'"
  2855. );
  2856. }
  2857. if ( $desc->{txt_sq}
  2858. && $desc->{scale_txt_long_m_sq} )
  2859. {
  2860. $desc->{txt_sq} = $desc->{scale_txt_long_m_sq} . lc( $desc->{txt_sq} );
  2861. Unit_Log3( $device, $reading, $odesc, 9,
  2862. "replaceTemplate $device $reading: RAttr txt_sq value rewritten by adding value from 'scale_txt_long_m_sq'"
  2863. );
  2864. }
  2865. # add square information to suffix_sq
  2866. if ( $desc->{suffix_sq}
  2867. && $desc->{scale_txt_sq} )
  2868. {
  2869. $desc->{suffix_sq} = $desc->{suffix_sq} . $desc->{scale_txt_sq};
  2870. Unit_Log3( $device, $reading, $odesc, 9,
  2871. "replaceTemplate $device $reading: RAttr suffix_sq value rewritten by adding value from 'scale_txt_sq'"
  2872. );
  2873. }
  2874. if ( $desc->{txt_sq}
  2875. && $desc->{scale_txt_long_sq} )
  2876. {
  2877. $desc->{txt_sq} = $desc->{scale_txt_long_sq} . lc( $desc->{txt_sq} );
  2878. Unit_Log3( $device, $reading, $odesc, 9,
  2879. "replaceTemplate $device $reading: RAttr txt_sq value rewritten by adding value from 'scale_txt_long_sq'"
  2880. );
  2881. }
  2882. # add time information to suffix_sq
  2883. if ( $desc->{suffix_sq}
  2884. && $desc->{scale_txt_t} )
  2885. {
  2886. $desc->{suffix_sq} = $desc->{suffix_sq} . $desc->{scale_txt_t};
  2887. Unit_Log3( $device, $reading, $odesc, 9,
  2888. "replaceTemplate $device $reading: RAttr suffix_sq value rewritten by adding value from 'scale_txt_t'"
  2889. );
  2890. }
  2891. if ( $desc->{txt_sq}
  2892. && $desc->{scale_txt_long_pl_t} )
  2893. {
  2894. $desc->{txt_pl_sq} =
  2895. $desc->{txt_sq} . lc( $desc->{scale_txt_long_pl_t} );
  2896. Unit_Log3( $device, $reading, $odesc, 9,
  2897. "replaceTemplate $device $reading: RAttr txt_pl_sq value rewritten by adding value from 'scale_txt_long_pl_t'"
  2898. );
  2899. }
  2900. if ( $desc->{txt_sq}
  2901. && $desc->{scale_txt_long_t} )
  2902. {
  2903. $desc->{txt_sq} = $desc->{txt_sq} . lc( $desc->{scale_txt_long_t} );
  2904. Unit_Log3( $device, $reading, $odesc, 9,
  2905. "replaceTemplate $device $reading: RAttr txt_sq value rewritten by adding value from 'scale_txt_long_t'"
  2906. );
  2907. }
  2908. # add metric name to suffix_cu
  2909. if ( $desc->{suffix_cu}
  2910. && $desc->{scale_txt_m_cu} )
  2911. {
  2912. $desc->{suffix_cu} = $desc->{scale_txt_m_cu} . $desc->{suffix_cu};
  2913. Unit_Log3( $device, $reading, $odesc, 9,
  2914. "replaceTemplate $device $reading: RAttr suffix_cu value rewritten by adding value from 'scale_txt_m_cu'"
  2915. );
  2916. }
  2917. if ( $desc->{txt_cu}
  2918. && $desc->{scale_txt_long_m_cu} )
  2919. {
  2920. $desc->{txt_cu} = $desc->{scale_txt_long_m_cu} . lc( $desc->{txt_cu} );
  2921. Unit_Log3( $device, $reading, $odesc, 9,
  2922. "replaceTemplate $device $reading: RAttr txt_cu value rewritten by adding value from 'scale_txt_long_m_cu'"
  2923. );
  2924. }
  2925. # add cubic information to suffix_cu
  2926. if ( $desc->{suffix_cu}
  2927. && $desc->{scale_txt_cu} )
  2928. {
  2929. $desc->{suffix_cu} = $desc->{suffix_cu} . $desc->{scale_txt_cu};
  2930. Unit_Log3( $device, $reading, $odesc, 9,
  2931. "replaceTemplate $device $reading: RAttr suffix_cu value rewritten by adding value from 'scale_txt_cu'"
  2932. );
  2933. }
  2934. if ( $desc->{txt_cu}
  2935. && $desc->{scale_txt_long_cu} )
  2936. {
  2937. $desc->{txt_cu} = $desc->{scale_txt_long_cu} . lc( $desc->{txt_cu} );
  2938. Unit_Log3( $device, $reading, $odesc, 9,
  2939. "replaceTemplate $device $reading: RAttr txt_cu value rewritten by adding value from 'scale_txt_long_cu'"
  2940. );
  2941. }
  2942. # add time information to suffix_cu
  2943. if ( $desc->{suffix_cu}
  2944. && $desc->{scale_txt_t} )
  2945. {
  2946. $desc->{suffix_cu} = $desc->{suffix_cu} . $desc->{scale_txt_t};
  2947. Unit_Log3( $device, $reading, $odesc, 9,
  2948. "replaceTemplate $device $reading: RAttr suffix_cu value rewritten by adding value from 'scale_txt_t'"
  2949. );
  2950. }
  2951. if ( $desc->{txt_cu}
  2952. && $desc->{scale_txt_long_pl_t} )
  2953. {
  2954. $desc->{txt_pl_cu} =
  2955. $desc->{txt_cu} . lc( $desc->{scale_txt_long_pl_t} );
  2956. Unit_Log3( $device, $reading, $odesc, 9,
  2957. "replaceTemplate $device $reading: RAttr txt_pl_cu value rewritten by adding value from 'scale_txt_long_pl_t'"
  2958. );
  2959. }
  2960. if ( $desc->{txt_cu}
  2961. && $desc->{scale_txt_long_t} )
  2962. {
  2963. $desc->{txt_cu} = $desc->{txt_cu} . lc( $desc->{scale_txt_long_t} );
  2964. Unit_Log3( $device, $reading, $odesc, 9,
  2965. "replaceTemplate $device $reading: RAttr txt_cu value rewritten by adding value from 'scale_txt_long_t'"
  2966. );
  2967. }
  2968. ###############################
  2969. # generate short text string
  2970. #
  2971. # find text template
  2972. $txt = '%value%' . chr(0x00A0) . '%suffix%' if ( !$desc->{symbol} );
  2973. $txt = '%value%' . chr(0x202F) . '%symbol%' if ( $desc->{symbol} );
  2974. $txt = '%value%' . chr(0x202F) . '%symbol%' if ( $desc->{symbol} );
  2975. $txt = $desc->{tmpl} if ( $desc->{tmpl} );
  2976. $txt = '%txt%'
  2977. if ( defined( $desc->{txt} ) && !looks_like_number($value) );
  2978. Unit_Log3( $device, $reading, $odesc, 9,
  2979. "replaceTemplate $device $reading: detected txt template: $txt" );
  2980. # Replace all %text% placeholders with text value found
  2981. # in old style READINGS.
  2982. # Normally only TIME & VAL would be available but some modules might have
  2983. # extended this and we want people to be able to make use of it.
  2984. if ( $r && $reading && $r->{$reading} ) {
  2985. foreach my $k ( keys %{ $r->{$reading} } ) {
  2986. next if ( ref( $r->{$reading}{$k} ) );
  2987. $txt =~ s/%$k%/$r->{$reading}{$k}/g;
  2988. Unit_Log3( $device, $reading, $odesc, 10,
  2989. "replaceTemplate $device $reading: RAttr txt: replacing '%$k%'"
  2990. );
  2991. }
  2992. }
  2993. # Replace all %text% placeholders with text value found
  2994. # in matching reading desc hash keys
  2995. foreach my $k ( keys %{$desc} ) {
  2996. my $vdm = $desc->{$k};
  2997. next if ( ref($vdm) );
  2998. $vdm = UConv::decimal_mark( $vdm, $desc->{decimal_mark} )
  2999. if ( defined( $desc->{decimal_mark} ) );
  3000. $txt =~ s/%$k%/$vdm/g;
  3001. Unit_Log3( $device, $reading, $odesc, 10,
  3002. "replaceTemplate $device $reading: RAttr txt: replacing '%$k%'" );
  3003. }
  3004. return ($txt) unless (wantarray);
  3005. ###############################
  3006. # generate long text string in plural
  3007. #
  3008. # find text template
  3009. if ( looks_like_number($value)
  3010. && ( $value eq "0" || $value > 1 || $value < -1 )
  3011. && $desc->{txt_long_pl} )
  3012. {
  3013. $txt_long = '%value%' . chr(0x00A0) . '%txt_long_pl%';
  3014. $txt_long = $desc->{tmpl_long_pl}
  3015. if ( $desc->{tmpl_long_pl} );
  3016. }
  3017. elsif (looks_like_number($value)
  3018. && ( $value eq "0" || $value > 1 || $value < -1 )
  3019. && $desc->{txt_pl} )
  3020. {
  3021. $txt_long = '%value%' . chr(0x00A0) . '%txt_pl%';
  3022. $txt_long = $desc->{tmpl_long_pl}
  3023. if ( $desc->{tmpl_long_pl} );
  3024. }
  3025. ###############################
  3026. # generate long text string in singular
  3027. #
  3028. # find text template
  3029. elsif ( $desc->{txt_long} ) {
  3030. $txt_long = '%value%' . chr(0x00A0) . '%txt_long%';
  3031. $txt_long = $desc->{tmpl_long}
  3032. if ( $desc->{tmpl_long} );
  3033. }
  3034. elsif ( $desc->{txt} ) {
  3035. $txt_long = '%value%' . chr(0x00A0) . '%txt%';
  3036. $txt_long = $desc->{tmpl_long}
  3037. if ( $desc->{tmpl_long} );
  3038. }
  3039. # for either plural or singular long text string
  3040. if ($txt_long) {
  3041. Unit_Log3( $device, $reading, $odesc, 9,
  3042. "replaceTemplate $device $reading: detected txt_long template: $txt_long"
  3043. );
  3044. # Replace all %text% placeholders with text value found
  3045. # in old style READINGS.
  3046. # Normally only TIME & VAL would be available but some modules might have
  3047. # extended this and we want people to be able to make use of it.
  3048. if ( $r && $reading && $r->{$reading} ) {
  3049. foreach my $k ( keys %{ $r->{$reading} } ) {
  3050. next if ( ref( $r->{$reading}{$k} ) );
  3051. $txt_long =~ s/%$k%/$r->{$reading}{$k}/g;
  3052. Unit_Log3( $device, $reading, $odesc, 10,
  3053. "replaceTemplate $device $reading: RAttr txt_long: replacing '%$k%'"
  3054. );
  3055. }
  3056. }
  3057. # Replace all %text% placeholders with text value found
  3058. # in matching reading desc hash keys
  3059. foreach my $k ( keys %{$desc} ) {
  3060. my $vdm = $desc->{$k};
  3061. next if ( ref($vdm) );
  3062. $vdm = UConv::decimal_mark( $vdm, $desc->{decimal_mark} )
  3063. if ( defined( $desc->{decimal_mark} ) );
  3064. $txt_long =~ s/%$k%/$vdm/g;
  3065. Unit_Log3( $device, $reading, $odesc, 10,
  3066. "replaceTemplate $device $reading: RAttr txt_long: replacing '%$k%'"
  3067. );
  3068. }
  3069. }
  3070. my $unit =
  3071. $desc->{symbol} ? $desc->{symbol}
  3072. : (
  3073. $desc->{suffix} ? $desc->{suffix}
  3074. : ( $desc->{txt} ? $desc->{txt} : undef )
  3075. );
  3076. $txt = Encode::encode_utf8($txt) if ( defined($txt) );
  3077. $txt_long = Encode::encode_utf8($txt_long) if ( defined($txt_long) );
  3078. $unit = Encode::encode_utf8($unit) if ( defined($unit) );
  3079. return ( $txt, $txt_long, $unit );
  3080. }
  3081. sub Unit_verifyValueNumber($$) {
  3082. my ( $value, $scope ) = @_;
  3083. my $log;
  3084. my $value_num;
  3085. my $verified = 0;
  3086. foreach ( keys %{$scope} ) {
  3087. next
  3088. if ( $_ !~ /^(regex|eq|minValue|maxValue|lt|gt|le|ge)$/ );
  3089. $verified = 1;
  3090. if ( !looks_like_number($value) ) {
  3091. if ( $_ eq 'regex' ) {
  3092. $log .= " '$value' does not match regex $scope->{$_}."
  3093. if ( $value !~ /$scope->{$_}/ );
  3094. $value_num = $scope->{value_num}
  3095. if ( defined( $scope->{value_num} ) );
  3096. }
  3097. elsif ( $_ eq 'eq' ) {
  3098. if ( $value ne $scope->{eq} ) {
  3099. $log .= " $value is not equal to $scope->{eq}.";
  3100. $value = $scope->{eq}
  3101. if ( !$scope->{keep} || $scope->{strict} );
  3102. }
  3103. $value_num = $scope->{value_num}
  3104. if ( defined( $scope->{value_num} ) );
  3105. }
  3106. elsif ( !$scope->{regex} && !defined( $scope->{eq} ) ) {
  3107. $log .= " '$value' is not a number."
  3108. if ( !$scope->{empty} && !$scope->{empty_replace} );
  3109. $value = "0"
  3110. if ( !$scope->{keep} && !$scope->{empty_replace} );
  3111. $value = $scope->{empty_replace}
  3112. if ( defined( $scope->{empty_replace} ) );
  3113. last;
  3114. }
  3115. }
  3116. elsif ( $_ eq 'minValue' ) {
  3117. if ( $value < $scope->{$_} ) {
  3118. $log .= " $value is lesser than $scope->{$_}.";
  3119. $value = $scope->{$_}
  3120. if ( !$scope->{keep} || $scope->{strict} );
  3121. }
  3122. }
  3123. elsif ( $_ eq 'maxValue' ) {
  3124. if ( $value > $scope->{$_} ) {
  3125. $log .= " $value is greater than $scope->{$_}.";
  3126. $value = $scope->{$_}
  3127. if ( !$scope->{keep} || $scope->{strict} );
  3128. }
  3129. }
  3130. elsif ( $_ eq 'lt' ) {
  3131. if ( $value >= $scope->{$_} ) {
  3132. $log .= " $value is not $_ $scope->{$_}.";
  3133. $value = $scope->{$_}
  3134. if ( !$scope->{keep} || $scope->{strict} );
  3135. }
  3136. }
  3137. elsif ( $_ eq 'le' ) {
  3138. if ( $value > $scope->{$_} ) {
  3139. $log .= " $value is not $_ $scope->{$_}.";
  3140. $value = $scope->{$_}
  3141. if ( !$scope->{keep} || $scope->{strict} );
  3142. }
  3143. }
  3144. elsif ( $_ eq 'gt' ) {
  3145. if ( $value <= $scope->{$_} ) {
  3146. $log .= " $value is not $_ $scope->{$_}.";
  3147. $value = $scope->{$_}
  3148. if ( !$scope->{keep} || $scope->{strict} );
  3149. }
  3150. }
  3151. elsif ( $_ eq 'ge' ) {
  3152. if ( $value < $scope->{$_} ) {
  3153. $log .= " $value is not $_ $scope->{$_}.";
  3154. $value = $scope->{$_}
  3155. if ( !$scope->{keep} || $scope->{strict} );
  3156. }
  3157. }
  3158. elsif ( $_ eq 'eq' ) {
  3159. if ( $value ne $scope->{$_} ) {
  3160. $log .= " $value is not equal to $scope->{$_}.";
  3161. $value = $scope->{$_}
  3162. if ( !$scope->{keep} || $scope->{strict} );
  3163. }
  3164. else {
  3165. $log = undef;
  3166. last;
  3167. }
  3168. }
  3169. }
  3170. return ( $verified, $value, $value_num, $log );
  3171. }
  3172. # format a number according to desc and optional format.
  3173. sub formatValue($$$;$$$$) {
  3174. my ( $device, $reading, $value, $desc, $format, $scope, $lang ) = @_;
  3175. $lang = "en" if ( !$lang );
  3176. my $lang_base = $lang;
  3177. $lang_base =~ s/^(\w+)(_.*)$/$1/;
  3178. my $value_num;
  3179. if ( !defined($value)
  3180. || ref($value)
  3181. || AttrVal( $device, "showUnits", 1 ) eq "0" )
  3182. {
  3183. Unit_Log3( $device, $reading, $desc, 10,
  3184. "formatValue $device $reading: explicit return of original value" );
  3185. return $value;
  3186. }
  3187. $desc = readingsDesc( $device, $reading )
  3188. if ( !$desc || !ref($desc) );
  3189. if ( !$format && ( !$desc || ref($desc) ne 'HASH' )
  3190. || keys %{$desc} < 1 )
  3191. {
  3192. Unit_Log3( $device, $reading, $desc, 10,
  3193. "formatValue $device $reading: "
  3194. . "no readings description found, returning original value" );
  3195. return $value;
  3196. }
  3197. # source value language
  3198. my $slang = "en";
  3199. $slang = $desc->{lang} if ( $desc && $desc->{lang} );
  3200. my $slang_base = $slang;
  3201. $slang_base =~ s/^(\w+)(_.*)$/$1/;
  3202. # factor
  3203. if ( $desc && $desc->{factor} ) {
  3204. if ( ref( $desc->{factor} ) || !looks_like_number( $desc->{factor} ) ) {
  3205. Unit_Log3( $device, $reading, $desc, 5,
  3206. "formatValue $device $reading: ERROR: "
  3207. . "RAttr factor is not numeric" );
  3208. }
  3209. elsif ( looks_like_number($value) ) {
  3210. Unit_Log3( $device, $reading, $desc, 9,
  3211. "formatValue $device $reading: "
  3212. . "multiply original numeric value with factor "
  3213. . $desc->{factor} );
  3214. $value *= $desc->{factor};
  3215. }
  3216. else {
  3217. Unit_Log3( $device, $reading, $desc, 8,
  3218. "formatValue $device $reading: factor "
  3219. . "multiplication failed - '$value' is not a number" );
  3220. }
  3221. }
  3222. $format = $desc->{format}
  3223. if ( !$format && $desc && $desc->{format} );
  3224. $scope = $desc->{scope} if ( !$scope && $desc && $desc->{scope} );
  3225. # language handling for scope
  3226. if ( ref($scope) eq "HASH" && defined( $scope->{$slang} ) ) {
  3227. my $v;
  3228. $v = $scope->{$slang};
  3229. $scope = undef;
  3230. $scope = $v;
  3231. Unit_Log3( $device, $reading, $desc, 8,
  3232. "formatValue $device $reading: RAttr scope: "
  3233. . "value replaced by language specific version ($slang)" );
  3234. }
  3235. elsif ( ref($scope) eq "HASH" && defined( $scope->{$slang_base} ) ) {
  3236. my $v;
  3237. $v = $scope->{$slang_base};
  3238. $scope = undef;
  3239. $scope = $v;
  3240. Unit_Log3( $device, $reading, $desc, 8,
  3241. "formatValue $device $reading: RAttr scope: "
  3242. . "value replaced by language specific version ($slang_base)" );
  3243. }
  3244. Unit_Log3( $device, $reading, $desc, 9,
  3245. "formatValue $device $reading: scope dump:\n" . Dumper($scope) )
  3246. if ($scope);
  3247. ################################
  3248. # scope:
  3249. # Check for value to be in correct scope
  3250. #
  3251. # Use user defined subroutine
  3252. if ( ref($scope) eq 'CODE' && &$scope ) {
  3253. Unit_Log3( $device, $reading, $desc, 9,
  3254. "formatValue $device $reading: scope: "
  3255. . "running external subroutine $scope()" );
  3256. ( $value, $value_num ) = $scope->($value);
  3257. }
  3258. # scope was defined as HASH
  3259. elsif ( ref($scope) eq 'HASH' ) {
  3260. Unit_Log3( $device, $reading, $desc, 9,
  3261. "formatValue $device $reading: scope: "
  3262. . "verifying '$value' based on HASH structure" );
  3263. my ( $log, $verified );
  3264. ( $verified, $value, $value_num, $log ) =
  3265. Unit_verifyValueNumber( $value, $scope );
  3266. Unit_Log3( $device, $reading, $desc, 4,
  3267. "formatValue $device $reading: scope: WARNING -$log" )
  3268. if ($log);
  3269. }
  3270. # scope was defined as ARRAY so let's assume value
  3271. # to be the index for that array to convert
  3272. # this index to a text string.
  3273. # 'value_num' will be defined here to help harmonising text values over
  3274. # different reading names representing similar/comparable content in
  3275. # some way.
  3276. elsif ( ref($scope) eq 'ARRAY' ) {
  3277. Unit_Log3( $device, $reading, $desc, 9,
  3278. "formatValue $device $reading: scope: "
  3279. . "verifying value '$value' based on ARRAY structure" );
  3280. # value found as index within array.
  3281. # assuming this scope was defined as string in regex format
  3282. if ( looks_like_number($value)
  3283. && defined( $scope->[$value] )
  3284. && !ref( $scope->[$value] )
  3285. && $value =~ /$scope->[$value]/gmi )
  3286. {
  3287. $value_num = $value;
  3288. # some language handling
  3289. # to replace original value with language specific
  3290. # and FHEM harmonised value
  3291. #
  3292. # If specified language was found
  3293. if ( ref( $desc->{txt} ) eq "HASH"
  3294. && ref( $desc->{txt}{$lang} ) eq "ARRAY"
  3295. && defined( $desc->{txt}{$lang}[$value] ) )
  3296. {
  3297. Unit_Log3( $device, $reading, $desc, 8,
  3298. "formatValue $device $reading: scope: rattr value: "
  3299. . "replaced by language specific value from 'txt' ($lang)"
  3300. );
  3301. $value = $desc->{txt}{$lang}[$value];
  3302. }
  3303. # also try base language
  3304. elsif (ref( $desc->{txt} ) eq "HASH"
  3305. && ref( $desc->{txt}{$lang_base} ) eq "ARRAY"
  3306. && defined( $desc->{txt}{$lang_base}[$value] ) )
  3307. {
  3308. Unit_Log3( $device, $reading, $desc, 8,
  3309. "formatValue $device $reading: scope: rattr value: "
  3310. . "replaced by language specific value from 'txt' ($lang_base)"
  3311. );
  3312. $value = $desc->{txt}{$lang_base}[$value];
  3313. }
  3314. # fallback to english
  3315. elsif (ref( $desc->{txt} ) eq "HASH"
  3316. && ref( $desc->{txt}{en} ) eq "ARRAY"
  3317. && defined( $desc->{txt}{en}[$value] ) )
  3318. {
  3319. Unit_Log3( $device, $reading, $desc, 8,
  3320. "formatValue $device $reading: scope: rattr value: "
  3321. . "replaced by language specific value from 'txt' (en / default language)"
  3322. );
  3323. $value = $desc->{txt}{en}[$value];
  3324. }
  3325. # if there is no language defined at all
  3326. elsif ( ref( $desc->{txt} ) eq "ARRAY"
  3327. && defined( $desc->{txt}[$value] ) )
  3328. {
  3329. Unit_Log3( $device, $reading, $desc, 8,
  3330. "formatValue $device $reading: scope: rattr value: "
  3331. . "replaced by value from 'txt'" );
  3332. $value = $desc->{txt}[$value];
  3333. }
  3334. # if there is no language defined at all
  3335. elsif ( !ref( $desc->{txt} )
  3336. && defined( $desc->{txt} ) )
  3337. {
  3338. Unit_Log3( $device, $reading, $desc, 8,
  3339. "formatValue $device $reading: scope: rattr value: "
  3340. . "replaced by plane value from 'txt'" );
  3341. $value = $desc->{txt};
  3342. }
  3343. # if there is no txt definition at all
  3344. # arrays are unbalanced
  3345. else {
  3346. Unit_Log3( $device, $reading, $desc, 7,
  3347. "formatValue $device $reading: scope: ERROR - "
  3348. . "unbalanced number of items in arrays" );
  3349. }
  3350. }
  3351. else {
  3352. my $i = 0;
  3353. foreach ( @{$scope} ) {
  3354. #TODO
  3355. if ( !ref($_) && $value =~ /$_/gmi ) {
  3356. $value_num = $i;
  3357. # some language handling
  3358. # to replace original value with language specific
  3359. # and FHEM harmonised value
  3360. #
  3361. # If specified language was found
  3362. if ( ref( $desc->{txt} ) eq "HASH"
  3363. && ref( $desc->{txt}{$lang} ) eq "ARRAY"
  3364. && defined( $desc->{txt}{$lang}[$i] ) )
  3365. {
  3366. Unit_Log3( $device, $reading, $desc, 8,
  3367. "formatValue $device $reading: scope: rattr value: "
  3368. . "replaced by language specific value from 'txt' ($lang)"
  3369. );
  3370. $value = $desc->{txt}{$lang}[$i];
  3371. }
  3372. # also try base language
  3373. elsif (ref( $desc->{txt} ) eq "HASH"
  3374. && ref( $desc->{txt}{$lang_base} ) eq "ARRAY"
  3375. && defined( $desc->{txt}{$lang_base}[$i] ) )
  3376. {
  3377. Unit_Log3( $device, $reading, $desc, 8,
  3378. "formatValue $device $reading: scope: rattr value: "
  3379. . "replaced by language specific value from 'txt' ($lang_base)"
  3380. );
  3381. $value = $desc->{txt}{$lang_base}[$i];
  3382. }
  3383. # fallback to english
  3384. elsif (ref( $desc->{txt} ) eq "HASH"
  3385. && ref( $desc->{txt}{en} ) eq "ARRAY"
  3386. && defined( $desc->{txt}{en}[$i] ) )
  3387. {
  3388. Unit_Log3( $device, $reading, $desc, 8,
  3389. "formatValue $device $reading: scope: rattr value: "
  3390. . "replaced by language specific value from 'txt' (en / default language)"
  3391. );
  3392. $value = $desc->{txt}{en}[$i];
  3393. }
  3394. # if there is no language defined at all
  3395. elsif ( ref( $desc->{txt} ) eq "ARRAY"
  3396. && defined( $desc->{txt}[$i] ) )
  3397. {
  3398. Unit_Log3( $device, $reading, $desc, 8,
  3399. "formatValue $device $reading: scope: rattr value: "
  3400. . "replaced by value from 'txt'" );
  3401. $value = $desc->{txt}[$i];
  3402. }
  3403. # if there is no language defined at all
  3404. elsif ( !ref( $desc->{txt} )
  3405. && defined( $desc->{txt} ) )
  3406. {
  3407. Unit_Log3( $device, $reading, $desc, 8,
  3408. "formatValue $device $reading: scope: rattr value: "
  3409. . "replaced by plane value from 'txt'" );
  3410. $value = $desc->{txt};
  3411. }
  3412. # if there is no txt definition at all
  3413. # arrays are unbalanced
  3414. else {
  3415. $value = $1 if ( defined($1) );
  3416. if ( !defined($1) ) {
  3417. Unit_Log3( $device, $reading, $desc, 7,
  3418. "formatValue device $reading: scope: ERROR - "
  3419. . "missing txt value or regex output (i=$i)"
  3420. );
  3421. }
  3422. }
  3423. last;
  3424. }
  3425. #TODO
  3426. elsif ( ref($_) eq "HASH" ) {
  3427. if ( !looks_like_number($value) && $_->{regex} ) {
  3428. Unit_Log3( $device, $reading, $desc, 9,
  3429. "formatValue $device $reading: scope: "
  3430. . "searching numeric value for string '$value' (i=$i)"
  3431. );
  3432. if ( $value =~ /$_->{regex}/ ) {
  3433. if ( defined( $_->{value_num} ) ) {
  3434. Unit_Log3( $device, $reading, $desc, 9,
  3435. "formatValue $device $reading: scope: "
  3436. . "static numeric value found in HASH" );
  3437. $value_num->[0] = $i;
  3438. $value_num->[1] = $_->{value_num};
  3439. }
  3440. else {
  3441. Unit_Log3( $device, $reading, $desc, 9,
  3442. "formatValue $device $reading: scope: "
  3443. . "assuming indirect numeric value from ARRAY index number"
  3444. );
  3445. $value_num = $i;
  3446. }
  3447. last;
  3448. }
  3449. }
  3450. #TODO: wenn nummer out of scope, dann muss ein maximalwert gesetzt sein
  3451. else {
  3452. Unit_Log3( $device, $reading, $desc, 9,
  3453. "formatValue $device $reading: scope: "
  3454. . "verifying numeric value '$value' (i=$i)" );
  3455. my ( $verified, $tval, $tval_num, $log ) =
  3456. Unit_verifyValueNumber( $value, $_ );
  3457. if ($log) {
  3458. Unit_Log3( $device, $reading, $desc, 4,
  3459. "formatValue $device $reading: scope: WARNING -$log"
  3460. );
  3461. }
  3462. elsif ( $verified && !$log ) {
  3463. if ( defined($tval_num) ) {
  3464. Unit_Log3( $device, $reading, $desc, 9,
  3465. "formatValue $device $reading: scope: "
  3466. . "static numeric value found in HASH" );
  3467. $value_num->[0] = $i;
  3468. $value_num->[1] = $tval_num;
  3469. }
  3470. else {
  3471. Unit_Log3( $device, $reading, $desc, 9,
  3472. "formatValue $device $reading: scope: "
  3473. . "assuming indirect numeric value from ARRAY index number"
  3474. );
  3475. $value_num = $i;
  3476. }
  3477. $value = $tval;
  3478. last;
  3479. }
  3480. }
  3481. }
  3482. $i++;
  3483. }
  3484. }
  3485. }
  3486. # scope was defined as string, let's assume it's in regex format
  3487. elsif ( defined($scope) && $scope ne "" && $value =~ /$scope/gmi ) {
  3488. # if regex matches and returns a $1, let's assume this is
  3489. # by intention to replace something
  3490. if ( defined($1) ) {
  3491. Unit_Log3( $device, $reading, $desc, 9,
  3492. "formatValue $device $reading: scope: "
  3493. . "'$value' replaced by regex $scope with result from variable \$1"
  3494. );
  3495. $value = $1;
  3496. }
  3497. }
  3498. # scope definition present but value seems to be out of regex scope
  3499. elsif ( defined($scope) && $scope ne "" ) {
  3500. Unit_Log3( $device, $reading, $desc, 8,
  3501. "formatValue $device $reading: scope: WARNING - "
  3502. . "'$value' does not match regex $scope" );
  3503. }
  3504. # format
  3505. #
  3506. if ( $format && !looks_like_number($value) ) {
  3507. Unit_Log3( $device, $reading, $desc, 8,
  3508. "formatValue $device $reading: format: ERROR - $value is not a number"
  3509. )
  3510. if ( ref($scope) eq 'HASH'
  3511. && !$scope->{empty}
  3512. && !$scope->{empty_replace} );
  3513. }
  3514. elsif ( ref($format) eq 'CODE' && &$format ) {
  3515. $value = $format->($value);
  3516. }
  3517. elsif ( ref($format) eq 'HASH' ) {
  3518. my $v = $value;
  3519. foreach my $l ( sort { $b <=> $a } keys( %{$format} ) ) {
  3520. next
  3521. if ( ref( $format->{$l} ) ne 'HASH'
  3522. || !$format->{$l}{rescale} );
  3523. if ( $v >= $l ) {
  3524. my $rescale = $format->{$l}{rescale};
  3525. $value *= $rescale if ($rescale);
  3526. $value = sprintf( $format->{$l}{format}, $value )
  3527. if ( $format->{$l}{format} );
  3528. last;
  3529. }
  3530. }
  3531. }
  3532. elsif ( ref($format) eq 'ARRAY' ) {
  3533. Unit_Log3( $device, $reading, $desc, 8,
  3534. "formatValue($device:$reading:$desc->{rtype})"
  3535. . " format not implemented: ARRAY" );
  3536. }
  3537. elsif ($format) {
  3538. my $rescale = $desc->{rescale};
  3539. $value *= $rescale if ($rescale);
  3540. $value = sprintf( $format, $value );
  3541. }
  3542. $desc->{value}{$lang} = $value;
  3543. $desc->{value_num} = $value_num if ( defined($value_num) );
  3544. my ( $txt, $txt_long, $unit ) =
  3545. replaceTemplate( $device, $reading, $desc, $lang, $value );
  3546. $desc->{value_txt}{$lang} = $txt;
  3547. $desc->{value_txt_long}{$lang} = $txt_long
  3548. if ( defined($txt_long) );
  3549. delete $desc->{value_txt_long}{$lang}
  3550. if (!defined($txt_long)
  3551. && defined( $desc->{value_txt_long}{$lang} ) );
  3552. return ( $txt, $txt_long, $value, $value_num, $unit ) if (wantarray);
  3553. return $value
  3554. if ( ( defined( $desc->{showUnits} ) && $desc->{showUnits} eq "2" )
  3555. || AttrVal( $device, "showUnits", 1 ) eq "2" );
  3556. return $txt_long
  3557. if ( $desc->{showLong} && !$desc->{showShort} );
  3558. return $txt;
  3559. }
  3560. # find desc for device:reading
  3561. sub readingsDesc($;$) {
  3562. my ( $device, $reading ) = @_;
  3563. my $desc = getCombinedKeyValAttr( $device, "readingsDesc", $reading );
  3564. my $rtype;
  3565. $rtype = $desc->{rtype} if ( $desc->{rtype} );
  3566. if ( $rtype && defined( $rtypes->{$rtype} ) ) {
  3567. # copy information from other hashes until 3rd level
  3568. foreach my $k ( keys %{ $rtypes->{$rtype} } ) {
  3569. if ( ref( $rtypes->{$rtype}{$k} ) eq "HASH" ) {
  3570. foreach my $k2 ( keys %{ $rtypes->{$rtype}{$k} } ) {
  3571. if ( ref( $rtypes->{$rtype}{$k}{$k2} ) eq "HASH" ) {
  3572. foreach ( keys %{ $rtypes->{$rtype}{$k}{$k2} } ) {
  3573. delete $desc->{$k}{$k2}{$_}
  3574. if ( $desc->{$k}{$k2}{$_} );
  3575. $desc->{$k}{$k2}{$_} =
  3576. $rtypes->{$rtype}{$k}{$k2}{$_};
  3577. }
  3578. }
  3579. else {
  3580. delete $desc->{$k}{$k2} if ( $desc->{$k}{$k2} );
  3581. $desc->{$k}{$k2} = $rtypes->{$rtype}{$k}{$k2};
  3582. }
  3583. }
  3584. }
  3585. else {
  3586. delete $desc->{$k} if ( $desc->{$k} );
  3587. $desc->{$k} = $rtypes->{$rtype}{$k};
  3588. }
  3589. }
  3590. foreach ( 'ref', 'ref_t', 'ref_sq', 'ref_cu' ) {
  3591. my $suffix = $_;
  3592. $suffix =~ s/^[a-z]+//;
  3593. if ( defined( $desc->{$_} ) ) {
  3594. my $ref = $desc->{$_};
  3595. if ( !defined( $rtypes->{$ref} ) ) {
  3596. Log 1, "readingsDesc($rtype) broken reference $_";
  3597. next;
  3598. }
  3599. foreach my $k ( keys %{ $rtypes->{$ref} } ) {
  3600. next
  3601. if ( $k =~ /^scale/ )
  3602. ; # exclude scales from referenced rtype
  3603. if ( !defined( $desc->{$k} ) ) {
  3604. $desc->{$k} = $rtypes->{$ref}{$k};
  3605. }
  3606. else {
  3607. $desc->{ $k . $suffix } = $rtypes->{$ref}{$k}
  3608. if ( !defined( $desc->{ $k . $suffix } ) );
  3609. }
  3610. }
  3611. }
  3612. }
  3613. if ( $desc->{scale_m} ) {
  3614. my $ref = $desc->{scale_m};
  3615. foreach my $k ( keys %{ $scales_m->{$ref} } ) {
  3616. $desc->{$k} = $scales_m->{$ref}{$k}
  3617. if ( !defined( $desc->{$k} ) );
  3618. }
  3619. }
  3620. if ( $desc->{scale_sq} ) {
  3621. foreach my $k ( keys %{$scales_sq} ) {
  3622. $desc->{$k} = $scales_sq->{$k}
  3623. if ( !defined( $desc->{$k} ) );
  3624. }
  3625. my $ref = $desc->{scale_sq};
  3626. foreach my $k ( keys %{ $scales_m->{$ref} } ) {
  3627. $desc->{ $k . "_sq" } = $scales_m->{$ref}{$k}
  3628. if ( !defined( $desc->{ $k . "_sq" } ) );
  3629. }
  3630. }
  3631. if ( $desc->{scale_cu} ) {
  3632. foreach my $k ( keys %{$scales_cu} ) {
  3633. $desc->{$k} = $scales_cu->{$k}
  3634. if ( !defined( $desc->{$k} ) );
  3635. }
  3636. my $ref = $desc->{scale_cu};
  3637. foreach my $k ( keys %{ $scales_m->{$ref} } ) {
  3638. $desc->{ $k . "_cu" } = $scales_m->{$ref}{$k}
  3639. if ( !defined( $desc->{ $k . "_cu" } ) );
  3640. }
  3641. }
  3642. if ( $desc->{scale_t} ) {
  3643. my $ref = $desc->{scale_t};
  3644. foreach my $k ( keys %{ $scales_t->{$ref} } ) {
  3645. $desc->{$k} = $scales_t->{$ref}{$k}
  3646. if ( !defined( $desc->{$k} ) );
  3647. }
  3648. }
  3649. $desc->{ref_base} = 999 if ( !defined( $desc->{ref_base} ) );
  3650. my $ref = $desc->{ref_base};
  3651. foreach my $k ( keys %{ $rtype_base->{$ref} } ) {
  3652. $desc->{$k} = $rtype_base->{$ref}{$k}
  3653. if ( !defined( $desc->{$k} ) );
  3654. }
  3655. }
  3656. Unit_Log3( $device, $reading, $desc, 10,
  3657. "readingsDesc $device $reading:\n" . Dumper($desc) );
  3658. return $desc;
  3659. }
  3660. # format device:reading with optional default value and optional desc and optional format
  3661. sub formatReading($$;$$$$$) {
  3662. my ( $device, $reading, $default, $desc, $format, $scope, $lang ) = @_;
  3663. $desc = readingsDesc( $device, $reading ) if ( !$desc );
  3664. my $value = ReadingsVal( $device, $reading, undef );
  3665. $value = $default if ( !defined($value) );
  3666. return formatValue( $device, $reading, $value, $desc, $format,
  3667. $scope, $lang );
  3668. }
  3669. # return unit symbol for device:reading
  3670. sub readingsUnit($$;$$$) {
  3671. my ( $device, $reading, $long, $combined, $desc ) = @_;
  3672. $desc = readingsDesc( $device, $reading ) if ( !$desc );
  3673. return (
  3674. $desc->{suffix} ? $desc->{suffix} : undef,
  3675. $desc->{symbol} ? $desc->{symbol} : undef,
  3676. $desc->{txt} ? $desc->{txt} : undef
  3677. ) if (wantarray);
  3678. my ( $txt, $txt_long, $value, $value_num ) =
  3679. formatReading( $device, $reading, "", $desc );
  3680. $txt =~ s/\s*$value\s*//;
  3681. $txt_long =~ s/\s*$value\s*//;
  3682. return "$txt_long ($txt)"
  3683. if ( $combined
  3684. && defined($txt_long)
  3685. && $txt_long ne ""
  3686. && defined($txt)
  3687. && $txt ne "" );
  3688. return $txt_long
  3689. if ( $long && defined($txt_long) && $txt_long ne "" );
  3690. return $txt if ( defined($txt) && $txt ne "" );
  3691. return '';
  3692. }
  3693. # return dimension symbol for device:reading
  3694. sub readingsShortname($$) {
  3695. my ( $device, $reading ) = @_;
  3696. if ( my $desc = readingsDesc( $device, $reading ) ) {
  3697. return $desc->{formula_symbol} if ( $desc->{formula_symbol} );
  3698. return $desc->{dimension}
  3699. if ( $desc->{dimension} && $desc->{dimension} =~ /^[A-Z]+$/ );
  3700. return $desc->{symbol} if ( $desc->{symbol} );
  3701. }
  3702. return $reading;
  3703. }
  3704. # format device STATE readings according to stateFormat and optional units
  3705. sub makeSTATE($;$$) {
  3706. my ( $device, $stateFormat, $withUnits ) = @_;
  3707. $stateFormat = '' if ( !$stateFormat );
  3708. my $hash = $defs{$device};
  3709. return $stateFormat if ( !$hash );
  3710. $stateFormat = AttrVal( $device, 'stateFormat', undef )
  3711. if ( !$stateFormat );
  3712. return '' if ( !$stateFormat );
  3713. # filter own function name to avoid loops
  3714. $stateFormat =~ s/{.*}//mg
  3715. if ( $stateFormat =~ /makeSTATE/ );
  3716. # use all readings if stateFormat is empty
  3717. $stateFormat = join( ' ', sort keys %{ $hash->{READINGS} } )
  3718. if ( $stateFormat !~ /\w+/ );
  3719. my $txt;
  3720. if ( $stateFormat =~ m/^{(.*)}$/ ) {
  3721. $stateFormat = eval $1;
  3722. if ($@) {
  3723. $stateFormat = "Error evaluating $device stateFormat: $@";
  3724. Log 1, $stateFormat;
  3725. }
  3726. }
  3727. else {
  3728. my $r = $hash->{READINGS};
  3729. my %usedShortnames;
  3730. while ( $stateFormat =~ /\b([A-Za-z\d_\.-]+):?([A-Za-z\d_\.-]+)?\b/g ) {
  3731. $txt .= " " if ($txt);
  3732. if ( defined( $r->{$1} ) ) {
  3733. my $sname = readingsShortname( $device, $1 );
  3734. $usedShortnames{$sname}++
  3735. if ( $usedShortnames{$sname} );
  3736. $usedShortnames{$sname} = 1
  3737. if ( !$usedShortnames{$sname} );
  3738. if ( $2 && $2 ne "" ) {
  3739. $txt .= "$2: ";
  3740. }
  3741. elsif ( $usedShortnames{$sname} > 1 ) {
  3742. $txt .= "$sname" . $usedShortnames{$sname} . ": ";
  3743. }
  3744. else {
  3745. $txt .= "$sname: ";
  3746. }
  3747. if ($withUnits) {
  3748. $txt .= formatReading( $device, $1 );
  3749. }
  3750. else {
  3751. $txt .= ( formatReading( $device, $1 ) )[2];
  3752. }
  3753. }
  3754. else {
  3755. $txt .= $1;
  3756. $txt .= ":$2" if ($2);
  3757. }
  3758. }
  3759. return $txt;
  3760. }
  3761. return $stateFormat;
  3762. }
  3763. # get combined hash for settings from module, device, global and device attributes
  3764. sub getCombinedKeyValAttr($;$$) {
  3765. my ( $name, $attribute, $reading ) = @_;
  3766. my $d = $defs{$name} if ( $defs{$name} );
  3767. my $m = $modules{ $d->{TYPE} } if ( $d && $d->{TYPE} );
  3768. my $g = $defs{"global"};
  3769. # join hashes until 3rd level
  3770. my $desc;
  3771. if ( $m && $m->{$attribute} && ref( $m->{$attribute} ) eq "HASH" ) {
  3772. Log3( $name, 5,
  3773. "getCombinedKeyValAttr $name $reading: including HASH from module X_Initialize() function"
  3774. );
  3775. foreach my $k ( keys %{ $m->{$attribute} } ) {
  3776. if ( ref( $m->{$attribute}{$k} ) eq "HASH" ) {
  3777. foreach my $k2 ( keys %{ $m->{$attribute}{$k} } ) {
  3778. if ( ref( $m->{$attribute}{$k}{$k2} ) eq "HASH" ) {
  3779. foreach ( keys %{ $m->{$attribute}{$k}{$k2} } ) {
  3780. delete $desc->{$k}{$k2}{$_}
  3781. if ( $desc->{$k}{$k2}{$_} );
  3782. $desc->{$k}{$k2}{$_} =
  3783. $m->{$attribute}{$k}{$k2}{$_};
  3784. }
  3785. }
  3786. else {
  3787. delete $desc->{$k}{$k2} if ( $desc->{$k}{$k2} );
  3788. $desc->{$k}{$k2} = $m->{$attribute}{$k}{$k2};
  3789. }
  3790. }
  3791. }
  3792. else {
  3793. delete $desc->{$_} if ( $desc->{$k} );
  3794. $desc->{$_} = $m->{$attribute}{$k};
  3795. }
  3796. }
  3797. }
  3798. if ( $g && $g->{$attribute} && ref( $g->{$attribute} ) eq "HASH" ) {
  3799. Log3( $name, 5,
  3800. "getCombinedKeyValAttr $name $reading: including HASH from global attribute $attribute"
  3801. );
  3802. foreach my $k ( keys %{ $g->{$attribute} } ) {
  3803. if ( ref( $g->{$attribute}{$k} ) eq "HASH" ) {
  3804. foreach my $k2 ( keys %{ $g->{$attribute}{$k} } ) {
  3805. if ( ref( $g->{$attribute}{$k}{$k2} ) eq "HASH" ) {
  3806. foreach ( keys %{ $g->{$attribute}{$k}{$k2} } ) {
  3807. delete $desc->{$k}{$k2}{$_}
  3808. if ( $desc->{$k}{$k2}{$_} );
  3809. $desc->{$k}{$k2}{$_} =
  3810. $g->{$attribute}{$k}{$k2}{$_};
  3811. }
  3812. }
  3813. else {
  3814. delete $desc->{$k}{$k2} if ( $desc->{$k}{$k2} );
  3815. $desc->{$k}{$k2} = $g->{$attribute}{$k}{$k2};
  3816. }
  3817. }
  3818. }
  3819. else {
  3820. delete $desc->{$_} if ( $desc->{$k} );
  3821. $desc->{$_} = $g->{$attribute}{$k};
  3822. }
  3823. }
  3824. }
  3825. if ( $d && $d->{$attribute} && ref( $d->{$attribute} ) eq "HASH" ) {
  3826. Log3( $name, 5,
  3827. "getCombinedKeyValAttr $name $reading: including HASH from device attribute $attribute"
  3828. );
  3829. foreach my $k ( keys %{ $d->{$attribute} } ) {
  3830. if ( ref( $d->{$attribute}{$k} ) eq "HASH" ) {
  3831. foreach my $k2 ( keys %{ $d->{$attribute}{$k} } ) {
  3832. if ( ref( $d->{$attribute}{$k}{$k2} ) eq "HASH" ) {
  3833. foreach ( keys %{ $d->{$attribute}{$k}{$k2} } ) {
  3834. delete $desc->{$k}{$k2}{$_}
  3835. if ( $desc->{$k}{$k2}{$_} );
  3836. $desc->{$k}{$k2}{$_} =
  3837. $d->{$attribute}{$k}{$k2}{$_};
  3838. }
  3839. }
  3840. else {
  3841. delete $desc->{$k}{$k2} if ( $desc->{$k}{$k2} );
  3842. $desc->{$k}{$k2} = $d->{$attribute}{$k}{$k2};
  3843. }
  3844. }
  3845. }
  3846. else {
  3847. delete $desc->{$_} if ( $desc->{$k} );
  3848. $desc->{$_} = $d->{$attribute}{$k};
  3849. }
  3850. }
  3851. }
  3852. return
  3853. if (
  3854. keys %{$desc} < 1
  3855. || (
  3856. $reading
  3857. && ( !defined( $desc->{$reading} )
  3858. || keys %{ $desc->{$reading} } < 1 )
  3859. )
  3860. );
  3861. return $desc->{$reading} if ($reading);
  3862. return $desc;
  3863. }
  3864. # save key/value pair to device attribute
  3865. sub setKeyValAttr($$$$$) {
  3866. my ( $name, $attribute, $reading, $key, $value ) = @_;
  3867. my $d = $defs{$name} if ( $defs{$name} );
  3868. my $ret;
  3869. return
  3870. if (
  3871. !$d
  3872. || ( defined( $d->{$attribute} )
  3873. && defined( $d->{$attribute}{$reading} )
  3874. && defined( $d->{$attribute}{$reading}{$key} )
  3875. && $d->{$attribute}{$reading}{$key} eq $value )
  3876. );
  3877. # rtype
  3878. if ( $key =~ /^rtype$/i ) {
  3879. $key = lc($key);
  3880. # Show all possible values
  3881. if ( $value && $value eq "?" ) {
  3882. return "CURRENTLY KNOWN READING TYPES\n\n"
  3883. . PrintHash( $rtypes, 0 );
  3884. }
  3885. # find rtype based on reading name
  3886. elsif ( !defined($value) || $value eq "" ) {
  3887. $value = rname2rtype( $name, $reading );
  3888. $ret =
  3889. "Set auto-detected $key for device $name $reading: " . $value
  3890. if ($value);
  3891. }
  3892. my $curr;
  3893. no strict "refs";
  3894. $curr = &$attribute( $name, $reading ) if (&$attribute);
  3895. use strict "refs";
  3896. return
  3897. if (
  3898. !defined($value)
  3899. || $value eq ""
  3900. || ( defined($curr)
  3901. && defined( $curr->{$key} )
  3902. && $curr->{$key} eq $value )
  3903. || ( defined( $d->{$attribute} )
  3904. && defined( $d->{$attribute}{$reading} )
  3905. && defined( $d->{$attribute}{$reading}{$key} )
  3906. && $d->{$attribute}{$reading}{$key} eq $value )
  3907. );
  3908. return
  3909. "Invalid value $value for $key: Cannot be assigned to device $name $reading"
  3910. if ( !defined( $rtypes->{$value} ) );
  3911. $ret =
  3912. "Changed value $key='"
  3913. . $d->{$attribute}{$reading}{$key}
  3914. . "' for device $name $reading to: "
  3915. . $value
  3916. if ( defined( defined( $d->{$attribute} ) )
  3917. && defined( $d->{$attribute}{$reading} )
  3918. && defined( $d->{$attribute}{$reading}{$key} )
  3919. && $d->{$attribute}{$reading}{$key} ne $value );
  3920. }
  3921. $d->{$attribute}{$reading}{$key} = $value;
  3922. # write attribute
  3923. $Data::Dumper::Terse = 1;
  3924. $Data::Dumper::Deepcopy = 1;
  3925. $Data::Dumper::Sortkeys = 1;
  3926. my $txt = Dumper( $d->{$attribute} );
  3927. $Data::Dumper::Terse = 0;
  3928. $Data::Dumper::Deepcopy = 0;
  3929. $Data::Dumper::Sortkeys = 0;
  3930. $txt =~ s/(=>\s*\{|['"],?)\s*\n\s*/$1 /gsm;
  3931. CommandAttr( undef, "$name $attribute $txt" );
  3932. return $ret;
  3933. }
  3934. sub deleteKeyValAttr($$$;$) {
  3935. my ( $name, $attribute, $reading, $key ) = @_;
  3936. my $d = $defs{$name} if ( $defs{$name} );
  3937. my $rt;
  3938. return
  3939. if ( !$d
  3940. || !defined( $d->{$attribute} )
  3941. || !defined( $d->{$attribute}{$reading} )
  3942. || ( $key && !defined( $d->{$attribute}{$reading}{$key} ) ) );
  3943. if ($key) {
  3944. $rt = " $key=" . $d->{$attribute}{$reading}{$key};
  3945. delete $d->{$attribute}{$reading}{$key};
  3946. }
  3947. delete $d->{$attribute}{$reading}
  3948. if ( !$key || keys %{ $d->{$attribute}{$reading} } < 1 );
  3949. # delete attribute
  3950. if ( keys %{ $d->{$attribute} } < 1 ) {
  3951. CommandDeleteAttr( undef, "$name $attribute" );
  3952. }
  3953. # write attribute
  3954. else {
  3955. $Data::Dumper::Terse = 1;
  3956. $Data::Dumper::Sortkeys = 1;
  3957. my $txt = Dumper( $d->{$attribute} );
  3958. $Data::Dumper::Terse = 0;
  3959. $Data::Dumper::Sortkeys = 0;
  3960. $txt =~ s/(=>\s*\{|[\'\"0-9],?)\s*\n\s*/$1 /gsm;
  3961. CommandAttr( undef, "$name $attribute $txt" );
  3962. }
  3963. return "Removed $reading$rt from attribute $name $attribute";
  3964. }
  3965. ################################################################
  3966. #
  3967. # Wrappers for commonly used core functions in device-specific modules.
  3968. #
  3969. ################################################################
  3970. # Generalized function for DbLog rtype support
  3971. sub Unit_DbLog_split($$) {
  3972. my ( $event, $name ) = @_;
  3973. my ( $reading, $value, $unit ) = "";
  3974. # exclude any multi-value events
  3975. if ( $event =~ /(.*: +.*: +.*)+/ ) {
  3976. Log3 $name, 5,
  3977. "Unit_DbLog_split $name: Ignoring multi-value event $event";
  3978. return undef;
  3979. }
  3980. # exclude sum/cum and avg events
  3981. elsif ( $event =~ /^.*(min|max|avg|sum|cum|avg\d+m|sum\d+m|cum\d+m): +.*/ )
  3982. {
  3983. Log3 $name, 5, "Unit_DbLog_split $name: Ignoring sum/avg event $event";
  3984. return undef;
  3985. }
  3986. # automatic text conversions through reading type
  3987. elsif ( $event =~ /^(.+): +(\S+) *(.*)/ ) {
  3988. $reading = $1;
  3989. my ( $txt, $txt_long, $val, $val_num, $symbol ) =
  3990. formatReading( $name, $reading, "" );
  3991. if ( defined($txt) && defined($reading) && defined($val) ) {
  3992. $txt =~ s/[\s\u202F\u00A0]*$val[\s\u202F\u00A0]*//;
  3993. $value = $val;
  3994. if ( !looks_like_number($val) && defined($val_num) ) {
  3995. if ( ref($val_num) eq "ARRAY" ) {
  3996. $value = $val_num->[1];
  3997. }
  3998. else {
  3999. $value = $val_num;
  4000. }
  4001. }
  4002. $unit = defined($symbol) ? $symbol : $txt;
  4003. }
  4004. }
  4005. # general event handling
  4006. if ( !defined($value)
  4007. && $event =~
  4008. /^(.+): +[\D]*(\d+\.?\d*)[\s\u202F\u00A0]*[\[\{\(]?[\s\u202F\u00A0]*([\w\°\%\^\/\\]*).*/
  4009. && defined($1)
  4010. && defined($2) )
  4011. {
  4012. $reading = $1;
  4013. $value = ReadingsNum( $name, $1, $2 );
  4014. $unit = defined($3) ? $3 : "";
  4015. }
  4016. unless ( defined($value) && looks_like_number($value) ) {
  4017. Unit_Log3( $name, $reading, undef, 10,
  4018. "Unit_DbLog_split $name: Ignoring event $event: value $value does not look like a number"
  4019. );
  4020. return undef;
  4021. }
  4022. Unit_Log3( $name, $reading, undef, 9,
  4023. "Unit_DbLog_split $name: Splitting event $event > reading=$reading value=$value unit=$unit"
  4024. );
  4025. return ( $reading, $value, $unit );
  4026. }
  4027. ################################################
  4028. # the new Log with integrated loglevel checking for readings
  4029. sub Unit_Log3($$$$$) {
  4030. my ( $dev, $rname, $desc, $loglevel, $text ) = @_;
  4031. $dev = $dev->{NAME} if ( defined($dev) && ref($dev) eq "HASH" );
  4032. $desc = readingsDesc( $dev, $rname )
  4033. if ( !$desc || !ref($desc) );
  4034. my $rloglevel = $loglevel;
  4035. if ( $desc
  4036. && ref($desc) eq "HASH"
  4037. && defined( my $rlevel = $desc->{verbose} ) )
  4038. {
  4039. return if ( $loglevel > $rlevel );
  4040. $rloglevel = $rloglevel - 9;
  4041. }
  4042. return Log3( $dev, $rloglevel, "RType: " . $text );
  4043. }
  4044. ################################################################
  4045. #
  4046. # User commands
  4047. #
  4048. ################################################################
  4049. # command: setreadingdesc
  4050. my %setreadingdeschash = (
  4051. Fn => "CommandSetReadingDesc",
  4052. Hlp =>
  4053. "<devspec> <readingspec> [noCheck] <key>=[<value>|?],set reading rtype information for <devspec> <reading>",
  4054. );
  4055. $cmds{setreadingdesc} = \%setreadingdeschash;
  4056. sub CommandSetReadingDesc($@) {
  4057. my ( $cl, $def ) = @_;
  4058. my $attribute = "readingsDesc";
  4059. my $namedef =
  4060. "where <devspec> is a single device name, a list separated by comma (,) or a regexp. See the devspec section in the commandref.html for details.\n"
  4061. . "<readingspec> can be a single reading name, a list separated by comma (,) or a regexp.";
  4062. my ( $a, $h ) = parseParams($def);
  4063. $a->[0] = ".*" if ( !$a->[0] );
  4064. $a->[1] = ".*" if ( !$a->[1] );
  4065. return
  4066. "Usage: setreadingdesc <devspec> <readingspec> [noCheck] <key>=[<value>|?]\n$namedef"
  4067. if ( $a->[0] eq "?" || $a->[1] eq "?" || !%{$h} );
  4068. my @rets;
  4069. my $last;
  4070. foreach my $name ( devspec2array( $a->[0], $cl ) ) {
  4071. if ( !defined( $defs{$name} ) ) {
  4072. push @rets, "Please define $name first";
  4073. next;
  4074. }
  4075. # do not check for existing reading
  4076. if ( $name eq "global"
  4077. || ( defined( $a->[2] ) && $a->[2] =~ /nocheck/i ) )
  4078. {
  4079. foreach ( keys %$h ) {
  4080. my $ret =
  4081. setKeyValAttr( $name, $attribute, $a->[1], $_, $h->{$_} );
  4082. push @rets, $ret if ( defined($ret) );
  4083. $last = 1 if ( $h->{$_} eq "?" || $h->{$_} eq "" );
  4084. }
  4085. next;
  4086. }
  4087. # check for existing reading
  4088. my $readingspec = '^' . $a->[1] . '$';
  4089. foreach my $reading (
  4090. grep { /$readingspec/ }
  4091. keys %{ $defs{$name}{READINGS} }
  4092. )
  4093. {
  4094. foreach ( keys %$h ) {
  4095. my $ret =
  4096. setKeyValAttr( $name, $attribute, $reading, $_, $h->{$_} );
  4097. push @rets, $ret if ( defined($ret) );
  4098. $last = 1 if ( $h->{$_} eq "?" || $h->{$_} eq "" );
  4099. }
  4100. }
  4101. last if ($last);
  4102. }
  4103. return join( "\n", @rets );
  4104. }
  4105. # command: deletereadingdesc
  4106. my %deletereadingdeschash = (
  4107. Fn => "CommandDeleteReadingDesc",
  4108. Hlp =>
  4109. "<devspec> <readingspec> [<keyspec>],delete key for <devspec> <reading>",
  4110. );
  4111. $cmds{deletereadingdesc} = \%deletereadingdeschash;
  4112. sub CommandDeleteReadingDesc($@) {
  4113. my ( $cl, $def ) = @_;
  4114. my $attribute = "readingsDesc";
  4115. my $namedef =
  4116. "where <devspec> is a single device name, a list separated by comma (,) or a regexp. See the devspec section in the commandref.html for details.\n"
  4117. . "<readingspec> and <keyspec> can be a single reading name, a list separated by comma (,) or a regexp.";
  4118. my ( $a, $h ) = parseParams($def);
  4119. $a->[0] = ".*" if ( !$a->[0] );
  4120. $a->[1] = ".*" if ( !$a->[1] );
  4121. $a->[2] = ".*" if ( !$a->[2] );
  4122. return
  4123. "Usage: deletereadingdesc <devspec> <readingspec> [<keyspec>]\n$namedef"
  4124. if ( $a->[0] eq "?" || $a->[1] eq "?" );
  4125. my @rets;
  4126. my $last;
  4127. foreach my $name ( devspec2array( $a->[0], $cl ) ) {
  4128. if ( !defined( $defs{$name} ) ) {
  4129. push @rets, "Please define $name first";
  4130. next;
  4131. }
  4132. my $readingspec = '^' . $a->[1] . '$';
  4133. foreach my $reading (
  4134. grep { /$readingspec/ }
  4135. keys %{ $defs{$name}{$attribute} }
  4136. )
  4137. {
  4138. my $keyspec = '^' . $a->[2] . '$';
  4139. foreach my $key (
  4140. grep { /$keyspec/ }
  4141. keys %{ $defs{$name}{$attribute}{$reading} }
  4142. )
  4143. {
  4144. my $ret = deleteKeyValAttr( $name, $attribute, $reading, $key );
  4145. push @rets, $ret if ( defined($ret) );
  4146. }
  4147. }
  4148. }
  4149. return join( "\n", @rets );
  4150. }
  4151. 1;