|
16 | 16 |
|
17 | 17 | NO_REMOTE_INSTALL_AVAILABLE_MSG = "<b>⚠️ Currently the Install process cannot be started from HomeAssistant. Please update it manually. ⚠️</b>"
|
18 | 18 |
|
| 19 | +UPDATE_RELEASE_SUMMARY_MAX_CHARS = 255 |
| 20 | + |
19 | 21 | class AppInfo(Entity):
|
20 | 22 | NAME = "AppInfo"
|
21 | 23 |
|
@@ -76,9 +78,48 @@ def UpdateCommandCustomPayload(self):
|
76 | 78 | "title": App.getName(),
|
77 | 79 | "name": App.getName(),
|
78 | 80 | "release_url": App.getUrlReleases(),
|
79 |
| - "release_summary": NO_REMOTE_INSTALL_AVAILABLE_MSG, |
| 81 | + "release_summary": + self.getReleaseNotes() |
80 | 82 | }
|
81 | 83 |
|
| 84 | + def getReleaseNotes(self): |
| 85 | + release_notes = NO_REMOTE_INSTALL_AVAILABLE_MSG + "<br><ul>" |
| 86 | + notes = App.crawlReleaseNotes().split("\n") |
| 87 | + notes = ["<li>" + note + "</li>" for note in notes if len(note) > 0] |
| 88 | + # Sort by length |
| 89 | + notes.sort(key=len) |
| 90 | + list_end = "</ul>" |
| 91 | + cannot_complete_msg = "<li>...</li>" |
| 92 | + |
| 93 | + # Append the list to the release notes until we have space |
| 94 | + # If no space, append "...": take into account that we can't place a note if then the next note is too long and |
| 95 | + # also there wouldn't be space for the "..." |
| 96 | + noteI = 0 |
| 97 | + end = False |
| 98 | + while noteI < len(notes) and not end: |
| 99 | + # Last note: don't need to take into account the possibility of adding "..." |
| 100 | + if noteI == len(notes) - 1: |
| 101 | + if len(release_notes) + len(notes[noteI]) + len(list_end) <= UPDATE_RELEASE_SUMMARY_MAX_CHARS: |
| 102 | + release_notes += notes[noteI] |
| 103 | + else: |
| 104 | + release_notes += cannot_complete_msg |
| 105 | + else: # not last note: can I add it ? If I add it, will I be able to add "..." if I won't be able to add the next note ? |
| 106 | + if len(release_notes) + len(notes[noteI]) + len(notes[noteI + 1]) + len(list_end) <= UPDATE_RELEASE_SUMMARY_MAX_CHARS: |
| 107 | + # Both this and next note can be added -> free to add this |
| 108 | + release_notes += notes[noteI] |
| 109 | + else: |
| 110 | + # The next note can't be added but the three dots can (and so also this note) -> Free to add this |
| 111 | + if len(release_notes) + len(notes[noteI]) + len(cannot_complete_msg) + len(list_end) <= UPDATE_RELEASE_SUMMARY_MAX_CHARS: |
| 112 | + release_notes += notes[noteI] |
| 113 | + else: |
| 114 | + # The three dots can't be added -> end |
| 115 | + release_notes += cannot_complete_msg |
| 116 | + end = True |
| 117 | + noteI += 1 |
| 118 | + |
| 119 | + |
| 120 | + release_notes += list_end |
| 121 | + return release_notes |
| 122 | + |
82 | 123 | def versionToInt(version: str):
|
83 | 124 | return int(''.join([i for i in version if i.isdigit()]))
|
84 | 125 |
|
|
0 commit comments