Skip to content

Commit

Permalink
delete IEchonetObject and replace to EchonetObjectSpecification
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Apr 1, 2024
1 parent 648fae1 commit 54fa866
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,33 @@

namespace Smdn.Net.EchonetLite.Appendix
{
internal class EchonetObjectSpecification : IEchonetObject
/// <summary>
/// ECHONET Lite オブジェクト
/// </summary>
public sealed class EchonetObjectSpecification
{
public EchonetObjectSpecification(byte classGroupCode, byte classCode)
/// <summary>
/// 指定されたクラスグループコード・クラスコードをもつ、未知のECHONET Lite オブジェクトを作成します。
/// </summary>
internal static EchonetObjectSpecification CreateUnknown(byte classGroupCode, byte classCode)
=> new(
classGroup: new(
code: classGroupCode,
name: "Unknown",
propertyName: "Unknown",
classes: Array.Empty<EchonetClassSpecification>(),
superClassName: null
),
@class: new(
isDefined: false,
code: classCode,
name: "Unknown",
propertyName: "Unknown"
),
properties: Array.Empty<EchonetPropertySpecification>()
);

internal EchonetObjectSpecification(byte classGroupCode, byte classCode)
{
ClassGroup =
SpecificationMaster.GetInstance().プロファイル.FirstOrDefault(p => p.Code == classGroupCode) ??
Expand Down Expand Up @@ -47,11 +71,25 @@ public EchonetObjectSpecification(byte classGroupCode, byte classCode)

Properties = properties;
}

private EchonetObjectSpecification(
EchonetClassGroupSpecification classGroup,
EchonetClassSpecification @class,
IReadOnlyList<EchonetPropertySpecification> properties
)
{
ClassGroup = classGroup;
Class = @class;
Properties = properties;
}

/// <summary>
/// クラスグループ情報
/// クラスグループコード
/// </summary>
public EchonetClassGroupSpecification ClassGroup { get; }
/// <summary>
/// クラス情報
/// クラスコード
/// </summary>
public EchonetClassSpecification Class { get; }
Expand Down
287 changes: 121 additions & 166 deletions src/Smdn.Net.EchonetLite.Appendix/Smdn.Net.EchonetLite/DeviceClasses.cs

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public static class Profiles
/// <summary>
/// 0xF0 ノードプロファイル
/// </summary>
public static IEchonetObject NodeProfile { get; } = new EchonetObjectSpecification(0x0E, 0xF0);
public static EchonetObjectSpecification NodeProfile { get; } = new(0x0E, 0xF0);

/// <summary>
/// クラス一覧
/// </summary>
public static IReadOnlyList<IEchonetObject> All { get; } = new IEchonetObject[]
{
public static IReadOnlyList<EchonetObjectSpecification> All { get; } =
[
NodeProfile,
};
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.ObjectModel;
using System.Linq;

using Smdn.Net.EchonetLite.Appendix;
using Smdn.Net.EchonetLite.Protocol;

namespace Smdn.Net.EchonetLite
Expand Down Expand Up @@ -35,7 +36,7 @@ public EchonetObject(EOJ eoj)
/// </summary>
/// <param name="classObject">オブジェクトクラス</param>
/// <param name="instanceCode"></param>
public EchonetObject(IEchonetObject classObject,byte instanceCode)
public EchonetObject(EchonetObjectSpecification classObject,byte instanceCode)
{
Spec = classObject ?? throw new ArgumentNullException(nameof(classObject));
InstanceCode = instanceCode;
Expand Down Expand Up @@ -107,7 +108,7 @@ internal void ResetProperties(IEnumerable<EchonetProperty> props)
/// クラスグループコード、クラスグループ名
/// ECHONET機器オブジェクト詳細規定がある場合、詳細仕様
/// </summary>
public IEchonetObject Spec { get; }
public EchonetObjectSpecification Spec { get; }
/// <summary>
/// インスタンスコード
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public void ClassGroup()
var obj = DeviceClasses.管理操作関連機器.コントローラ;

Assert.That(obj, Is.Not.Null);
Assert.That(obj.ClassGroup, Is.Not.Null, nameof(IEchonetObject.ClassGroup));
Assert.That(obj.ClassGroup, Is.Not.Null, nameof(EchonetObjectSpecification.ClassGroup));
Assert.That(obj.ClassGroup.Code, Is.EqualTo(0x05), nameof(EchonetClassGroupSpecification.Code));
Assert.That(obj.ClassGroup.Name, Is.EqualTo("管理・操作関連機器クラスグループ"), nameof(EchonetClassGroupSpecification.Name));
Assert.That(obj.ClassGroup.SuperClassName, Is.EqualTo("機器オブジェクトスーパークラス"), nameof(EchonetClassGroupSpecification.SuperClassName));
Assert.That(obj.ClassGroup.Classes, Is.Not.Empty, nameof(EchonetClassGroupSpecification.Classes));

Assert.That(obj.GetProperties, Is.Not.Null, nameof(IEchonetObject.GetProperties));
Assert.That(obj.GetProperties, Is.Not.Empty, nameof(IEchonetObject.GetProperties));
Assert.That(obj.GetProperties, Is.Not.Null, nameof(EchonetObjectSpecification.GetProperties));
Assert.That(obj.GetProperties, Is.Not.Empty, nameof(EchonetObjectSpecification.GetProperties));

Assert.That(obj.SetProperties, Is.Not.Null, nameof(IEchonetObject.SetProperties));
Assert.That(obj.SetProperties, Is.Not.Empty, nameof(IEchonetObject.SetProperties));
Assert.That(obj.SetProperties, Is.Not.Null, nameof(EchonetObjectSpecification.SetProperties));
Assert.That(obj.SetProperties, Is.Not.Empty, nameof(EchonetObjectSpecification.SetProperties));

Assert.That(obj.AnnoProperties, Is.Not.Null, nameof(IEchonetObject.AnnoProperties));
Assert.That(obj.AnnoProperties, Is.Not.Empty, nameof(IEchonetObject.AnnoProperties));
Assert.That(obj.AnnoProperties, Is.Not.Null, nameof(EchonetObjectSpecification.AnnoProperties));
Assert.That(obj.AnnoProperties, Is.Not.Empty, nameof(EchonetObjectSpecification.AnnoProperties));
}

[Test]
Expand All @@ -39,18 +39,18 @@ public void Class()
var obj = DeviceClasses.管理操作関連機器.コントローラ;

Assert.That(obj, Is.Not.Null);
Assert.That(obj.Class, Is.Not.Null, nameof(IEchonetObject.Class));
Assert.That(obj.Class, Is.Not.Null, nameof(EchonetObjectSpecification.Class));
Assert.That(obj.Class.Code, Is.EqualTo(0xFF), nameof(EchonetClassSpecification.Code));
Assert.That(obj.Class.Name, Is.EqualTo("コントローラ"), nameof(EchonetClassSpecification.Name));

Assert.That(obj.GetProperties, Is.Not.Null, nameof(IEchonetObject.GetProperties));
Assert.That(obj.GetProperties, Is.Not.Empty, nameof(IEchonetObject.GetProperties));
Assert.That(obj.GetProperties, Is.Not.Null, nameof(EchonetObjectSpecification.GetProperties));
Assert.That(obj.GetProperties, Is.Not.Empty, nameof(EchonetObjectSpecification.GetProperties));

Assert.That(obj.SetProperties, Is.Not.Null, nameof(IEchonetObject.SetProperties));
Assert.That(obj.SetProperties, Is.Not.Empty, nameof(IEchonetObject.SetProperties));
Assert.That(obj.SetProperties, Is.Not.Null, nameof(EchonetObjectSpecification.SetProperties));
Assert.That(obj.SetProperties, Is.Not.Empty, nameof(EchonetObjectSpecification.SetProperties));

Assert.That(obj.AnnoProperties, Is.Not.Null, nameof(IEchonetObject.AnnoProperties));
Assert.That(obj.AnnoProperties, Is.Not.Empty, nameof(IEchonetObject.AnnoProperties));
Assert.That(obj.AnnoProperties, Is.Not.Null, nameof(EchonetObjectSpecification.AnnoProperties));
Assert.That(obj.AnnoProperties, Is.Not.Empty, nameof(EchonetObjectSpecification.AnnoProperties));
}

private static System.Collections.IEnumerable YieldTestCases_機器オブジェクトスーパークラスJson()
Expand All @@ -61,7 +61,7 @@ private static System.Collections.IEnumerable YieldTestCases_機器オブジェ
}

[TestCaseSource(nameof(YieldTestCases_機器オブジェクトスーパークラスJson))]
public void 機器オブジェクトスーパークラスJson(IEchonetObject obj)
public void 機器オブジェクトスーパークラスJson(EchonetObjectSpecification obj)
{
var epc80 = obj.GetProperties.FirstOrDefault(static prop => prop.Name == "動作状態");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void ノードプロファイル()
var p = Profiles.NodeProfile;

Assert.That(p, Is.Not.Null);
Assert.That(p.ClassGroup, Is.Not.Null, nameof(IEchonetObject.ClassGroup));
Assert.That(p.ClassGroup, Is.Not.Null, nameof(EchonetObjectSpecification.ClassGroup));
Assert.That(p.ClassGroup.Code, Is.EqualTo(0x0E), nameof(EchonetClassGroupSpecification.Code));
Assert.That(p.ClassGroup.Name, Is.EqualTo("プロファイルクラスグループ"), nameof(EchonetClassGroupSpecification.Name));
Assert.That(p.ClassGroup.SuperClassName, Is.EqualTo("プロファイルオブジェクトスーパークラス"), nameof(EchonetClassGroupSpecification.SuperClassName));
Expand Down

0 comments on commit 54fa866

Please sign in to comment.