Skip to content

Commit

Permalink
Merge pull request #111 from qJake/v1.1-prep
Browse files Browse the repository at this point in the history
Add unit override, bump deps
  • Loading branch information
qJake committed Jan 23, 2021
2 parents 2106e66 + b9d718f commit cbf0f26
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 8 deletions.
6 changes: 3 additions & 3 deletions HADotNet.CommandCenter/HADotNet.CommandCenter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<RuntimeIdentifiers>win10;alpine.3.10-x64;debian.10-arm</RuntimeIdentifiers>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<AssemblyVersion>1.0.22.0</AssemblyVersion>
<FileVersion>1.0.22.0</FileVersion>
<AssemblyVersion>1.0.24.0</AssemblyVersion>
<FileVersion>1.0.24.0</FileVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Deterministic>false</Deterministic>
Expand Down Expand Up @@ -39,7 +39,7 @@
<!-- Web Compiler is Windows-only. -->
<PackageReference Condition="'$(OS)' == 'Windows_NT'" Include="BuildWebCompiler" Version="1.12.405" />
<PackageReference Condition="'$(OS)' == 'Windows_NT'" Include="BuildBundlerMinifier" Version="3.2.449" />
<PackageReference Include="HADotNet.Core" Version="1.3.2" />
<PackageReference Include="HADotNet.Core" Version="1.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.6" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="3.1.6" />
Expand Down
9 changes: 7 additions & 2 deletions HADotNet.CommandCenter/Models/Config/Tiles/BaseTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace HADotNet.CommandCenter.Models.Config.Tiles
{
public abstract class BaseTile
{
/// <summary>
/// How big the max tile size can go - currently 8x.
/// </summary>
private const int MAX_TILE_SIZE = 8;

/// <summary>
/// Gets or sets the tile's admin name.
/// </summary>
Expand Down Expand Up @@ -73,7 +78,7 @@ public string IconClassName
}
}

public int GetTileSizeX(int tileSize, int padding) => Math.Min(Math.Max(SizeX, 1), 4) * tileSize + (Math.Min(Math.Max(SizeX, 1), 4) - 1) * padding;
public int GetTileSizeY(int tileSize, int padding) => Math.Min(Math.Max(SizeY, 1), 4) * tileSize + (Math.Min(Math.Max(SizeY, 1), 4) - 1) * padding;
public int GetTileSizeX(int tileSize, int padding) => Math.Min(Math.Max(SizeX, 1), MAX_TILE_SIZE) * tileSize + (Math.Min(Math.Max(SizeX, 1), MAX_TILE_SIZE) - 1) * padding;
public int GetTileSizeY(int tileSize, int padding) => Math.Min(Math.Max(SizeY, 1), MAX_TILE_SIZE) * tileSize + (Math.Min(Math.Max(SizeY, 1), MAX_TILE_SIZE) - 1) * padding;
}
}
6 changes: 6 additions & 0 deletions HADotNet.CommandCenter/Models/Config/Tiles/StateTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public class StateTile : BaseEntityTile
[Display(Name = "Override Label")]
public string OverrideLabel { get; set; }

/// <summary>
/// Gets or sets the override unit for this tile.
/// </summary>
[Display(Name = "Override Unit")]
public string OverrideUnit { get; set; }

/// <summary>
/// Gets or sets if the state should be displayed as a whole number, if appropriate.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions HADotNet.CommandCenter/Views/StateTile/Add.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
<span class="ui up pointing small red label" asp-validation-for="OverrideLabel"></span>
<p><small>By default, the entity's <em>friendly name</em> will be used. Enter an override if desired.</small></p>
</div>
<div class="field">
<label asp-for="OverrideUnit"></label>
<div class="ui left icon input">
<i class="font icon"></i>
<input asp-for="OverrideUnit" />
</div>
<span class="ui up pointing small red label" asp-validation-for="OverrideUnit"></span>
<p><small>By default, the entity's <em>default unit suffix</em> will be added. Enter a different unit suffix here if desired.</small></p>
</div>
<div class="field">
<label asp-for="DisplayTextOn"></label>
<div class="ui left icon input">
Expand Down
6 changes: 5 additions & 1 deletion HADotNet.CommandCenter/wwwroot/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ class StateTile extends Tile {
super.updateTile(t);
}
updateState(state) {
var _a;
//console.log("State received for: " + tile.name, state);
let label = state.new_state.attributes["friendly_name"].toString();
if (this.tile.overrideLabel) {
Expand All @@ -542,7 +543,10 @@ class StateTile extends Tile {
else if (this.tile.displayTextOn && value.toLowerCase() === 'on') {
value = this.tile.displayTextOn;
}
if (state.new_state.attributes["unit_of_measurement"]) {
if ((_a = this.tile.overrideUnit) === null || _a === void 0 ? void 0 : _a.length) {
value += this.tile.overrideUnit;
}
else if (state.new_state.attributes["unit_of_measurement"]) {
value += state.new_state.attributes["unit_of_measurement"].toString();
}
$(`#tile-${this.tile.name}`).find('span[value-state]').text(value);
Expand Down
2 changes: 1 addition & 1 deletion HADotNet.CommandCenter/wwwroot/js/app.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions HADotNet.CommandCenter/wwwroot/js/models/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ interface IStateTile extends ITile
/** Gets or sets a value indicating if decimal values should be rounded. */
roundDecimals: boolean;

/** Gets or sets the unit suffix text. */
overrideUnit: string;

/** Gets or sets a label that should be used when the entity is "on". */
displayTextOn: string;

Expand Down
6 changes: 5 additions & 1 deletion HADotNet.CommandCenter/wwwroot/js/tiles/state.tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class StateTile extends Tile
value = this.tile.displayTextOn;
}

if (state.new_state.attributes["unit_of_measurement"])
if (this.tile.overrideUnit?.length)
{
value += this.tile.overrideUnit;
}
else if (state.new_state.attributes["unit_of_measurement"])
{
value += state.new_state.attributes["unit_of_measurement"].toString();
}
Expand Down

0 comments on commit cbf0f26

Please sign in to comment.