-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccessory.cs
56 lines (45 loc) · 1.61 KB
/
Accessory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using HomeKit.Resources;
using HomeKit.Services;
namespace HomeKit
{
public class Accessory
{
private readonly string m_Name;
private readonly Category m_Category;
public int Aid { get; set; }
public List<Service> Services { get; } = new();
public Accessory(string name, Category category = Category.Other)
{
m_Name = name;
m_Category = category;
AddAccessoryInformationService();
}
protected virtual AccessoryServer PrepareServer(AccessoryServerOptions options)
{
var server = new AccessoryServer(options);
server.Accessories.Add(this);
return server;
}
public async Task<AccessoryServer> PublishAsync(AccessoryServerOptions options, CancellationToken? cancellationToken = null)
{
options.Name ??= m_Name;
options.Category ??= m_Category;
var server = PrepareServer(options);
await server.StartAsync(cancellationToken ?? CancellationToken.None);
return server;
}
private void AddAccessoryInformationService()
{
var info = new AccessoryInformationService();
info.Name.Value = m_Name;
info.SerialNumber.Value = m_Name + " SerialNumber";
info.Manufacturer.Value = m_Name + " Manufacturer";
info.Model.Value = m_Name + " Model";
info.FirmwareRevision.Value = "1.0";
Services.Add(info);
}
}
}