This code comes from https://github.com/Ape/samsungctl/issues/22#issuecomment-359063253