There’s no need to write your own add-on/operator if all you want to do is alter a single property from a key press - Blender provides operators that can do this for you.
As an example, this is how you set up a key binding to switch to a specifically named view layer: