A unified view on Hardyʼs paradox and the Clauser–Horne–Shimony–Holt inequality