-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from timia2109/feature/restructure
Feature/restructure
- Loading branch information
Showing
29 changed files
with
150 additions
and
247 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
MqttExport/BinaryImageStreamCreater.cs → EspUtilities/BinaryImageStreamCreater.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace DisplayUtil.EspUtilities; | ||
|
||
public static class EspUtilitiesInitExtension | ||
{ | ||
|
||
public static IHostApplicationBuilder AddEspUtilities(this IHostApplicationBuilder builder) | ||
{ | ||
builder.Services.AddScoped<EspImageProvider>(); | ||
return builder; | ||
} | ||
|
||
|
||
} |
4 changes: 1 addition & 3 deletions
4
MqttExport/RunLengthCompressor.cs → EspUtilities/RunLengthCompressor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using DisplayUtil.Template; | ||
using NetDaemon.HassModel; | ||
using Scriban.Runtime; | ||
|
||
namespace DisplayUtil.HomeAssistant; | ||
|
||
internal class HassTemplateExtender(IHaContext haContext) | ||
: ITemplateExtender | ||
{ | ||
public void Enrich(ScriptObject context, EnrichScope scope) | ||
{ | ||
// Hass Functions | ||
var hassObject = new ScriptObject(); | ||
hassObject.Import("get_state", GetState); | ||
hassObject.Import("get_attribute", GetAttribute); | ||
hassObject.Import("get_float_state", GetFloatState); | ||
context.Add("hass", hassObject); | ||
} | ||
|
||
private string? GetState(string entityId) | ||
{ | ||
var entity = haContext.GetState(entityId); | ||
return entity?.State; | ||
} | ||
|
||
private string? GetAttribute(string entityId, string attribute) | ||
{ | ||
var entity = haContext.GetState(entityId); | ||
var attributes = entity?.Attributes as Dictionary<string, object?>; | ||
object? value = null; | ||
|
||
if (!attributes?.TryGetValue(attribute, out value) ?? true) | ||
return null; | ||
|
||
return value?.ToString(); | ||
} | ||
|
||
private float GetFloatState(string entityId) | ||
{ | ||
var state = GetState(entityId); | ||
if (state == null) return 0f; | ||
return TemplateContextProvider.ToFloat(state); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Scriban; | ||
using Scriban.Runtime; | ||
|
||
namespace DisplayUtil.Template; | ||
|
||
/// <summary> | ||
/// Enum for the Scope of the Template | ||
/// </summary> | ||
public enum EnrichScope | ||
{ | ||
/// <summary> | ||
/// This template will used for ScreenRendering | ||
/// </summary> | ||
ScreenRendering | ||
} | ||
|
||
/// <summary> | ||
/// Extends the <see cref="TemplateContext"/> | ||
/// </summary> | ||
public interface ITemplateExtender | ||
{ | ||
/// <summary> | ||
/// Enriches the Template | ||
/// </summary> | ||
/// <param name="scriptObject">The used Context</param> | ||
/// <param name="scope">Scope of the enrichment</param> | ||
void Enrich(ScriptObject scriptObject, EnrichScope scope); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.