Skip to content

Commit 8c1f8dd

Browse files
authored
Merge pull request #113 from qJake/v1.1-prep
Basic caching and Calendar fix
2 parents e18cf4d + 2aca0af commit 8c1f8dd

12 files changed

Lines changed: 40 additions & 13 deletions

File tree

Docker/BuildHaccContainers.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$version = '1.0.25'
1+
$version = '1.0.26'
22

33
function Test-ExitCode ([int] $Expected = 0)
44
{

HADotNet.CommandCenter/Controllers/CalendarTileController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public CalendarTileController(IConfigStore configStore, EntityClient entityClien
2424
public async Task<IActionResult> Add()
2525
{
2626
ViewBag.Entities = (await EntityClient.GetEntities("calendar")).OrderBy(e => e).Select(e => new SelectListItem(e, e));
27+
ViewBag.CurrentConfig = await ConfigStore.GetConfigAsync();
28+
2729
return View();
2830
}
2931

@@ -35,6 +37,7 @@ public async Task<IActionResult> Edit([FromRoute] string page, [FromQuery] strin
3537
var tile = config[page].Tiles.FirstOrDefault(t => t.Name == name);
3638

3739
ViewBag.Entities = (await EntityClient.GetEntities("calendar")).OrderBy(e => e).Select(e => new SelectListItem(e, e));
40+
ViewBag.CurrentConfig = await ConfigStore.GetConfigAsync();
3841

3942
return View("Add", tile);
4043
}
@@ -48,6 +51,8 @@ public async Task<IActionResult> Save([FromRoute] string page, CalendarTile tile
4851
}
4952

5053
ViewBag.Entities = (await EntityClient.GetEntities("calendar")).OrderBy(e => e).Select(e => new SelectListItem(e, e));
54+
ViewBag.CurrentConfig = await ConfigStore.GetConfigAsync();
55+
5156
return View("Add", tile);
5257
}
5358
}

HADotNet.CommandCenter/HADotNet.CommandCenter.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<RuntimeIdentifiers>win10;alpine.3.10-x64;debian.10-arm</RuntimeIdentifiers>
66
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
77
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
8-
<AssemblyVersion>1.0.25.0</AssemblyVersion>
9-
<FileVersion>1.0.25.0</FileVersion>
8+
<AssemblyVersion>1.0.26.0</AssemblyVersion>
9+
<FileVersion>1.0.26.0</FileVersion>
1010
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1111
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
1212
<Deterministic>false</Deterministic>

HADotNet.CommandCenter/Hubs/TileHub.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ public class TileHub : Hub<ITileHub>
1212
{
1313
private StatesClient StatesClient { get; }
1414
public ServiceClient ServiceClient { get; }
15-
public CalendarClient CalendarClient { get; }
1615
public IConfigStore ConfigStore { get; }
1716

18-
public TileHub(StatesClient statesClient, ServiceClient serviceClient, CalendarClient calendarClient, IConfigStore configStore)
17+
public TileHub(StatesClient statesClient, ServiceClient serviceClient, IConfigStore configStore)
1918
{
2019
StatesClient = statesClient;
2120
ServiceClient = serviceClient;
2221
ConfigStore = configStore;
23-
CalendarClient = calendarClient;
2422
}
2523

2624
public async Task RequestTileState(string page, string tileName)
@@ -66,8 +64,14 @@ private async Task ProcessOverrides(BaseTile tile)
6664
{
6765
// Calendars use a special API that isn't (might not be?) exposed via the WebSocket API.
6866
case CalendarTile ct:
67+
// Required because for some reason, the calendar API is not available
68+
// via the "inside" supervisor API, only the "external" fully-qualified
69+
// API endpoint.
70+
var config = await ConfigStore.GetConfigAsync();
71+
var calClient = new CalendarClient(new Uri(config.Settings.OverrideAssetUri), config.Settings.AccessToken);
72+
6973
var state = await StatesClient.GetState(ct.EntityId);
70-
var calItems = await CalendarClient.GetEvents(ct.EntityId);
74+
var calItems = await calClient.GetEvents(ct.EntityId);
7175
await Clients.Caller.SendCalendarInfo(ct, state, calItems);
7276
break;
7377

HADotNet.CommandCenter/Services/JsonConfigStore.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class JsonConfigStore : IConfigStore
4040
private HaccOptions Options { get; }
4141
private ILogger<JsonConfigStore> Log { get; }
4242

43+
private static ConfigRoot CachedConfig { get; set; } = null;
44+
4345
public JsonConfigStore(IOptions<HaccOptions> haccOptions, ILogger<JsonConfigStore> log)
4446
{
4547
Options = haccOptions.Value;
@@ -67,6 +69,11 @@ public async Task ManipulateConfig(params Action<ConfigRoot>[] changes)
6769

6870
public async Task<ConfigRoot> GetConfigAsync()
6971
{
72+
if (CachedConfig != null)
73+
{
74+
return CachedConfig;
75+
}
76+
7077
if (CheckPermissions())
7178
{
7279
// One-time config Linux platform migration
@@ -106,6 +113,8 @@ public async Task<ConfigRoot> GetConfigAsync()
106113

107114
var cfg = JsonConvert.DeserializeObject<ConfigRoot>(contents, SerializerSettings);
108115

116+
CachedConfig = cfg;
117+
109118
return cfg;
110119
}
111120
else
@@ -116,6 +125,7 @@ public async Task<ConfigRoot> GetConfigAsync()
116125

117126
public async Task SaveConfigAsync(ConfigRoot config)
118127
{
128+
CachedConfig = null;
119129
if (CheckPermissions())
120130
{
121131
await File.WriteAllTextAsync(ConfigPath, JsonConvert.SerializeObject(config, SerializerSettings));

HADotNet.CommandCenter/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public void ConfigureServices(IServiceCollection services)
7373
services.AddScoped(_ => ClientFactory.GetClient<StatesClient>());
7474
services.AddScoped(_ => ClientFactory.GetClient<ServiceClient>());
7575
services.AddScoped(_ => ClientFactory.GetClient<DiscoveryClient>());
76-
services.AddScoped(_ => ClientFactory.GetClient<CalendarClient>());
7776

7877
services.AddSignalR()
7978
.AddNewtonsoftJsonProtocol();

HADotNet.CommandCenter/Views/Admin/Settings.cshtml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@
8989
<i class="globe icon"></i>
9090
<input asp-for="OverrideAssetUri" />
9191
</div>
92-
<small>If your image assets are not showing up correctly, you can enter a base URL to use. This URL must start with http(s):// and be accessible from your HACC device.</small>
92+
<small>
93+
If your image assets are not showing up correctly, you can enter a base URL to use. This URL must start with http(s):// and be accessible from your HACC device.<br /><br />
94+
This is also required if you want to use a <b>calendar</b> tile, due to the way the API call is handled.
95+
</small>
9396
<span class="ui up pointing small red label" asp-validation-for="OverrideAssetUri"></span>
9497
</div>
9598
</div>
@@ -128,7 +131,11 @@
128131
<i class="globe icon"></i>
129132
<input asp-for="OverrideAssetUri" />
130133
</div>
131-
<small>If your image assets are not showing up correctly, you can enter a base URL to use. This URL must start with http(s):// and be accessible from your HACC device.</small>
134+
<small>
135+
If your image assets are not showing up correctly, you can enter a base URL to use. This URL must start with http(s):// and be accessible from your HACC device.<br /><br />
136+
This is also required if you want to use a <b>calendar</b> tile, due to the way the API call is handled.<br /><br />
137+
For non-supervised environments, this can be (and is usually) the same as your <b>Home Assistant Base URL</b>, so try that if you aren't sure.
138+
</small>
132139
<span class="ui up pointing small red label" asp-validation-for="OverrideAssetUri"></span>
133140
</div>
134141
</div>

HADotNet.CommandCenter/Views/CalendarTile/Add.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@Html.Raw(header)
1414
</h1>
1515

16-
@if (SupervisorEnvironment.IsSupervisorAddon)
16+
@if (SupervisorEnvironment.IsSupervisorAddon && string.IsNullOrWhiteSpace((ViewBag.CurrentConfig as ConfigRoot)?.Settings?.OverrideAssetUri))
1717
{
1818
<div class="ui visible icon labeled warning message">
1919
<i class="triangle exclamation icon"></i>

HADotNet.CommandCenter/wwwroot/css/admin.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HADotNet.CommandCenter/wwwroot/css/dashboard.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ body.dashboard .debug-window {
155155
}
156156
.tile.tile-type--calendar {
157157
justify-content: flex-start !important;
158+
overflow-y: auto !important;
158159
}
159160
.tile.tile-type--calendar .top-label {
160161
display: block;

0 commit comments

Comments
 (0)