Expose session/last-used user and device IP on player rows. Filter retrieve_player_list by users, merge GET /Devices when include_offline is set, and resolve spoken names to HA media_player entities via player_links (device_id or IP). PlayNow still requires a live session.
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package emby
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func TestHostOf(t *testing.T) {
|
|
if HostOf("192.168.0.20:8096") != "192.168.0.20" {
|
|
t.Fatal(HostOf("192.168.0.20:8096"))
|
|
}
|
|
if HostOf("192.168.0.20") != "192.168.0.20" {
|
|
t.Fatal(HostOf("192.168.0.20"))
|
|
}
|
|
}
|
|
|
|
func TestGetDevicesWrapped(t *testing.T) {
|
|
c, srv := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/Devices" {
|
|
t.Errorf("path %s", r.URL.Path)
|
|
}
|
|
json.NewEncoder(w).Encode(map[string]any{
|
|
"Items": []map[string]any{
|
|
{"Id": "d9", "Name": "Lounge", "AppName": "Emby for Android", "LastUserName": "Gordon", "LastUserId": "u1", "IpAddress": "192.168.0.20"},
|
|
},
|
|
})
|
|
})
|
|
defer srv.Close()
|
|
devs, err := c.GetDevices(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(devs) != 1 || devs[0].LastUserName != "Gordon" {
|
|
t.Fatalf("%+v", devs)
|
|
}
|
|
}
|
|
|
|
func TestMergeOfflineDevices(t *testing.T) {
|
|
live := []PlayerSession{{DeviceID: "d1", SessionID: "s1", Online: true, UserName: "Gordon"}}
|
|
devs := []DeviceInfo{
|
|
{ID: "d1", Name: "dup"},
|
|
{ID: "d2", Name: "Bedroom", LastUserName: "Alice", IPAddress: "192.168.0.21"},
|
|
}
|
|
got := MergeOfflineDevices(live, devs)
|
|
if len(got) != 2 {
|
|
t.Fatalf("%+v", got)
|
|
}
|
|
if got[1].Online || got[1].UserName != "Alice" {
|
|
t.Fatalf("%+v", got[1])
|
|
}
|
|
}
|