Skip to content
Open
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
33 changes: 33 additions & 0 deletions docs/openrpc/openrpc/localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,39 @@
}
}
]
},
{
"name": "timeZone",
"tags": [
{
"name": "property:readonly"
},
{
"name": "capabilities",
"x-uses": [
"xrn:firebolt:capability:localization:time-zone"
]
}
],
"summary": "Get the IANA timezone of the device.",
"params": [],
"result": {
"name": "timeZone",
"summary": "The device timezone.",
"schema": {
"type": "string"
}
},
"examples": [
{
"name": "Default example",
"params": [],
"result": {
"name": "Default Result",
"value": "America/New_York"
}
}
]
}
],
"components": {
Expand Down
81 changes: 80 additions & 1 deletion docs/openrpc/the-spec/firebolt-open-rpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,39 @@
}
]
},
{
"name": "Localization.timeZone",
"tags": [
{
"name": "property:readonly"
},
{
"name": "capabilities",
"x-uses": [
"xrn:firebolt:capability:localization:time-zone"
]
}
],
"summary": "Get the IANA timezone of the device.",
"params": [],
"result": {
"name": "timeZone",
"summary": "The device timezone.",
"schema": {
"type": "string"
}
},
"examples": [
{
"name": "Default example",
"params": [],
"result": {
"name": "Default Result",
"value": "America/New_York"
}
}
]
},
{
"name": "Metrics.ready",
"tags": [
Expand Down Expand Up @@ -3396,6 +3429,52 @@
}
}
},
{
"name": "Localization.onTimeZoneChanged",
"tags": [
{
"name": "event",
"x-notifier": "Localization.onTimeZoneChanged",
"x-subscriber-for": "Localization.timeZone"
},
{
"name": "capabilities",
"x-uses": [
"xrn:firebolt:capability:localization:time-zone"
]
}
],
"summary": "Get the IANA timezone of the device.",
"params": [
{
"name": "listen",
"schema": {
"type": "boolean"
}
}
],
"examples": [
{
"name": "Default example",
"params": [
{
"name": "listen",
"value": true
}
],
"result": {
"name": "result",
"value": null
}
}
],
"result": {
"name": "result",
"schema": {
"type": "null"
}
}
},
{
"name": "Network.onConnectedChanged",
"summary": "Returns whether the device currently has a usable network connection.",
Expand Down Expand Up @@ -4040,4 +4119,4 @@
}
}
}
}
}
16 changes: 16 additions & 0 deletions include/firebolt/localization.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ class ILocalization
virtual Result<SubscriptionId>
subscribeOnPresentationLanguageChanged(std::function<void(const std::string&)>&& notification) = 0;

/**
* @brief Get the IANA timezone of the device.
*
* @retval The device timezone or error
*/
virtual Result<std::string> timeZone() const = 0;

/**
* @brief Subscribe on the change of TimeZoneChanged property
*
* @param[in] notification : The callback function
*
* @retval The subscriptionId or error
*/
virtual Result<SubscriptionId> subscribeOnTimeZoneChanged(std::function<void(const std::string&)>&& notification) = 0;

/**
* @brief Remove subscriber from subscribers list. This method is generic for
* all subscriptions
Expand Down
11 changes: 11 additions & 0 deletions src/localization_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ Result<std::string> LocalizationImpl::presentationLanguage() const
return helper_.get<Firebolt::JSON::String, std::string>("Localization.presentationLanguage");
}

Result<std::string> LocalizationImpl::timeZone() const
{
return helper_.get<Firebolt::JSON::String, std::string>("Localization.timeZone");
}

Result<SubscriptionId> LocalizationImpl::subscribeOnTimeZoneChanged(std::function<void(const std::string&)>&& notification)
{
return subscriptionManager_.subscribe<Firebolt::JSON::String>("Localization.onTimeZoneChanged",
std::move(notification));
}

Result<SubscriptionId> LocalizationImpl::subscribeOnCountryChanged(std::function<void(const std::string&)>&& notification)
{
return subscriptionManager_.subscribe<Firebolt::JSON::String>("Localization.onCountryChanged",
Expand Down
2 changes: 2 additions & 0 deletions src/localization_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ class LocalizationImpl : public ILocalization
Result<std::string> country() const override;
Result<std::vector<std::string>> preferredAudioLanguages() const override;
Result<std::string> presentationLanguage() const override;
Result<std::string> timeZone() const override;

// Events
Result<SubscriptionId> subscribeOnCountryChanged(std::function<void(const std::string&)>&& notification) override;
Result<SubscriptionId> subscribeOnPreferredAudioLanguagesChanged(
std::function<void(const std::vector<std::string>&)>&& notification) override;
Result<SubscriptionId>
subscribeOnPresentationLanguageChanged(std::function<void(const std::string&)>&& notification) override;
Result<SubscriptionId> subscribeOnTimeZoneChanged(std::function<void(const std::string&)>&& notification) override;

Result<void> unsubscribe(SubscriptionId id) override;
void unsubscribeAll() override;
Expand Down
37 changes: 37 additions & 0 deletions test/component/localizationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,40 @@ TEST_F(LocalizationCTest, subscribeOnPreferredPresentationLanguageChanged)
auto result = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().unsubscribe(id.value_or(0));
ASSERT_TRUE(result) << "error on unsubscribe ";
}

TEST_F(LocalizationCTest, TimeZone)
{
auto result = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().timeZone();
ASSERT_TRUE(result) << "error on get";

auto expectedValue = jsonEngine.get_value("Localization.timeZone").get<std::string>();
EXPECT_EQ(*result, expectedValue);
}

TEST_F(LocalizationCTest, subscribeOnTimeZoneChanged)
{
auto id = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().subscribeOnTimeZoneChanged(
[&](const std::string& timeZone)
{
EXPECT_EQ(timeZone, "America/New_York");
{
std::lock_guard<std::mutex> lock(mtx);
eventReceived = true;
}
cv.notify_one();
});

ASSERT_TRUE(id) << "error on subscribe ";
EXPECT_TRUE(id.has_value()) << "error on id";

// Trigger the event from the mock server
triggerEvent("Localization.onTimeZoneChanged", R"({"value":"America/New_York"})");
verifyEventReceived(mtx, cv, eventReceived);

SetUp();
triggerEvent("Localization.onTimeZoneChanged", R"({"value":12345})");
verifyEventNotReceived(mtx, cv, eventReceived);

auto result = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().unsubscribe(id.value_or(0));
ASSERT_TRUE(result) << "error on unsubscribe ";
}
28 changes: 28 additions & 0 deletions test/unit/localizationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,31 @@ TEST_F(LocalizationUTest, subscribeOnPresentationLanguageChanged)
auto result = localizationImpl_.unsubscribe(id.value_or(0));
ASSERT_TRUE(result) << "error on unsubscribe ";
}

TEST_F(LocalizationUTest, TimeZone)
{
auto expectedValue = jsonEngine.get_value("Localization.timeZone").get<std::string>();
mock("Localization.timeZone");

auto result = localizationImpl_.timeZone();
ASSERT_TRUE(result) << "error on get";

EXPECT_EQ(*result, expectedValue);
}

TEST_F(LocalizationUTest, TimeZoneBadResponse)
{
mock_with_response("Localization.timeZone", 12345);
ASSERT_FALSE(localizationImpl_.timeZone()) << "LocalizationImpl::timeZone() did not return an error";
}

TEST_F(LocalizationUTest, subscribeOnTimeZoneChanged)
{
mockSubscribe("Localization.onTimeZoneChanged");

auto id = localizationImpl_.subscribeOnTimeZoneChanged([](auto) {});
ASSERT_TRUE(id) << "error on subscribe ";
EXPECT_TRUE(id.has_value()) << "error on id";
auto result = localizationImpl_.unsubscribe(id.value_or(0));
ASSERT_TRUE(result) << "error on unsubscribe ";
}
Loading