Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix broken flow for changing brightness [no changelog] #4378

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ impl FlowController for SetBrightness {

static BRIGHTNESS: AtomicU8 = AtomicU8::new(0);

pub fn new_set_brightness(brightness: u8) -> Result<SwipeFlow, Error> {
pub fn new_set_brightness(brightness: Option<u8>) -> Result<SwipeFlow, Error> {
let brightness = brightness.unwrap_or(theme::backlight::get_backlight_normal());
let content_slider = Frame::left_aligned(
TR::brightness__title.into(),
NumberInputSliderDialog::new(
Expand Down Expand Up @@ -122,6 +123,7 @@ pub fn new_set_brightness(brightness: u8) -> Result<SwipeFlow, Error> {
)
.with_footer(TR::instructions__swipe_up.into(), None)
.with_swipe(Direction::Up, SwipeSettings::default())
.with_result_icon(theme::ICON_BULLET_CHECKMARK, theme::GREEN_LIGHT)
.map(move |_msg| Some(FlowMsg::Confirmed));

let res = SwipeFlow::new(&SetBrightness::Slider)?
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/ui/model_mercury/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut

extern "C" fn new_set_brightness(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let current: u8 = kwargs.get(Qstr::MP_QSTR_current)?.try_into()?;
let current: Option<u8> = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?;
let flow = flow::set_brightness::new_set_brightness(current)?;
Ok(LayoutObj::new_root(flow)?.into())
};
Expand Down
15 changes: 14 additions & 1 deletion tests/device_tests/test_msg_applysettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path

from ..input_flows import InputFlowConfirmAllWarnings
from ..input_flows import InputFlowConfirmAllWarnings, InputFlowSetBrightness

HERE = Path(__file__).parent.resolve()

Expand Down Expand Up @@ -421,3 +421,16 @@ def test_label_too_long(client: Client):
with pytest.raises(exceptions.TrezorFailure), client:
client.set_expected_responses([messages.Failure])
device.apply_settings(client, label="A" * 33)


@pytest.mark.models(skip=["legacy", "safe3"])
@pytest.mark.setup_client(pin=None)
def test_set_brightness(client: Client):
with client:
IF = InputFlowSetBrightness(client)
client.set_input_flow(IF.get())
# Set brightness to a default value
device.set_brightness(
client,
None,
)
17 changes: 17 additions & 0 deletions tests/input_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,23 @@ def input_flow_t3t1(self) -> BRGeneratorType:
self.debug.press_yes()


class InputFlowSetBrightness(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)

def input_flow_tt(self) -> BRGeneratorType:
self.debug.press_yes()
yield
self.debug.press_yes()
yield

def input_flow_t3t1(self) -> BRGeneratorType:
self.debug.swipe_up()
yield
self.debug.press_yes()
yield


class InputFlowShowAddressQRCode(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)
Expand Down
Loading