Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions docs/openrpc/the-spec/firebolt-open-rpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,39 @@
}
]
},
{
"name": "Device.name",
"summary": "Returns the device friendly name",
"params": [],
"tags": [
{
"name": "property:readonly"
},
{
"name": "capabilities",
"x-uses": [
"xrn:firebolt:capability:device:info"
]
}
],
"result": {
"name": "name",
"summary": "The device friendly name",
"schema": {
"type": "string"
}
},
"examples": [
{
"name": "Getting the device friendly name",
"params": [],
"result": {
"name": "Default Result",
"value": "Living Room TV"
}
}
]
},
{
"name": "Discovery.watched",
"summary": "Notify the platform that content was partially or completely watched",
Expand Down Expand Up @@ -4118,6 +4151,52 @@
}
}
},
{
"name": "Device.onNameChanged",
"summary": "Returns the device friendly name",
"params": [
{
"name": "listen",
"schema": {
"type": "boolean"
}
}
],
"tags": [
{
"name": "event",
"x-notifier": "Device.onNameChanged",
"x-subscriber-for": "Device.name"
},
{
"name": "capabilities",
"x-uses": [
"xrn:firebolt:capability:device:info"
]
}
],
"examples": [
{
"name": "Getting the device friendly name",
"params": [
{
"name": "listen",
"value": true
}
],
"result": {
"name": "result",
"value": null
}
}
],
"result": {
"name": "result",
"schema": {
"type": "string"
}
}
},
{
"name": "VideoOutput.resolution",
"summary": "Returns the resolution for the active video output",
Expand Down
14 changes: 14 additions & 0 deletions include/firebolt/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ class IDevice
*/
virtual Result<SubscriptionId>
subscribeOnDolbyAtmosExperienceAvailableChanged(std::function<void(bool)>&& notification) = 0;

/**
* @brief Returns the device friendly name
*
* @retval The device name string or error
*/
[[nodiscard]] virtual Result<std::string> name() const = 0;

/**
* @brief Subscribe to device friendly name changes
*
* @retval SubscriptionId or error
*/
virtual Result<SubscriptionId> subscribeOnNameChanged(std::function<void(const std::string&)>&& notification) = 0;
};

} // namespace Firebolt::Device
10 changes: 10 additions & 0 deletions src/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,14 @@ Result<SubscriptionId> DeviceImpl::subscribeOnDolbyAtmosExperienceAvailableChang
return subscriptionManager_.subscribe<Firebolt::JSON::Boolean>("Device.onDolbyAtmosExperienceAvailableChanged",
std::move(notification));
}

Result<std::string> DeviceImpl::name() const
{
return helper_.get<Firebolt::JSON::String, std::string>("Device.name");
}

Result<SubscriptionId> DeviceImpl::subscribeOnNameChanged(std::function<void(const std::string&)>&& notification)
{
return subscriptionManager_.subscribe<Firebolt::JSON::String>("Device.onNameChanged", std::move(notification));
}
} // namespace Firebolt::Device
3 changes: 3 additions & 0 deletions src/device_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class DeviceImpl : public IDevice
Result<SubscriptionId>
subscribeOnDolbyAtmosExperienceAvailableChanged(std::function<void(bool)>&& notification) override;

[[nodiscard]] Result<std::string> name() const override;
Result<SubscriptionId> subscribeOnNameChanged(std::function<void(const std::string&)>&& notification) override;

private:
Firebolt::Helpers::IHelper& helper_;
Firebolt::Helpers::SubscriptionManager subscriptionManager_;
Expand Down
1 change: 1 addition & 0 deletions src/firebolt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class FireboltAccessorImpl : public IFireboltAccessor
{
accessibility_.unsubscribeAll();
actions_.unsubscribeAll();
device_.unsubscribeAll();
lifecycle_.unsubscribeAll();
localization_.unsubscribeAll();
network_.unsubscribeAll();
Expand Down
9 changes: 9 additions & 0 deletions test/api_test_app/apis/deviceDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ DeviceDemo::DeviceDemo()
methods_.push_back("Device.deviceClass");
methods_.push_back("Device.dolbyAtmosExperienceAvailable");
methods_.push_back("Device.hdr");
methods_.push_back("Device.name");
methods_.push_back("Device.timeInActiveState");
methods_.push_back("Device.uid");
methods_.push_back("Device.uptime");
Expand Down Expand Up @@ -142,4 +143,12 @@ void DeviceDemo::runOption(const std::string& method)
std::cout << std::boolalpha << "Dolby Atmos Experience Available: " << *r << std::endl;
}
}
else if (method == "Device.name")
{
auto r = Firebolt::IFireboltAccessor::Instance().DeviceInterface().name();
if (succeed(r))
{
std::cout << "Device Name: " << *r << std::endl;
}
}
}
31 changes: 31 additions & 0 deletions test/component/deviceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,34 @@ TEST_F(DeviceCTest, SubscribeOnDolbyAtmosExperienceAvailableChanged)
auto result = Firebolt::IFireboltAccessor::Instance().DeviceInterface().unsubscribe(id.value());
verifyUnsubscribeResult(result);
}

TEST_F(DeviceCTest, Name)
{
auto expectedValue = jsonEngine.get_value("Device.name");
auto result = Firebolt::IFireboltAccessor::Instance().DeviceInterface().name();
ASSERT_TRUE(result) << "DeviceImpl::name() returned an error";
EXPECT_EQ(*result, expectedValue);
}

TEST_F(DeviceCTest, SubscribeOnNameChanged)
{
auto id = Firebolt::IFireboltAccessor::Instance().DeviceInterface().subscribeOnNameChanged(
[&](const std::string& value)
{
std::cout << "[Subscription] Device name changed" << '\n';
EXPECT_EQ(value, "Living Room TV");
{
std::lock_guard<std::mutex> lock(mtx);
eventReceived = true;
}
cv.notify_one();
});

verifyEventSubscription(id);

triggerEvent("Device.onNameChanged", R"("Living Room TV")");
verifyEventReceived(mtx, cv, eventReceived);

auto result = Firebolt::IFireboltAccessor::Instance().DeviceInterface().unsubscribe(id.value());
verifyUnsubscribeResult(result);
}
30 changes: 30 additions & 0 deletions test/unit/deviceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,33 @@ TEST_F(DeviceUTest, SubscribeOnDolbyAtmosExperienceAvailableChanged)

deviceImpl_.unsubscribe(*result);
}

TEST_F(DeviceUTest, Name)
{
mock("Device.name");
auto expectedValue = jsonEngine.get_value("Device.name");

auto result = deviceImpl_.name();
ASSERT_TRUE(result) << "DeviceImpl::name() returned an error";

EXPECT_EQ(*result, expectedValue);
}

TEST_F(DeviceUTest, NameBadResponse)
{
mock_with_response("Device.name", 12345);
ASSERT_FALSE(deviceImpl_.name()) << "DeviceImpl::name() did not return an error";
}

TEST_F(DeviceUTest, SubscribeOnNameChanged)
{
nlohmann::json expectedValue = 1;
mockSubscribe("Device.onNameChanged");

auto result = deviceImpl_.subscribeOnNameChanged([&](const std::string& /*value*/) {});

ASSERT_TRUE(result) << "DeviceImpl::subscribeOnNameChanged() returned an error";
EXPECT_EQ(*result, expectedValue);

deviceImpl_.unsubscribe(*result);
}
Loading