I ended up copy pasting the method from the Light unit with some slight adjustments:
def pbhubAnalogRead(pbhub, pbhub_address):
data = 0
max_val = 30
min_val = 750
for i in range(0, 10):
newdata = 750 - pbhub.analogRead(pbhub_address)
data += newdata
if newdata > max_val:
max_val = newdata
if newdata < min_val:
min_val = newdata
data -= (max_val + min_val)
data >>= 3
return round(max(1024 * data / 750, 0), 2)
pbhub = unit.get(unit.PBHUB, unit.PORTA)
light = pbhubAnalogRead(pbhub, 0x01)
The magic number min_val I got by pressing my finger on the light sensor (blocking all the light from entering) and reading the analog value. The value 750 seems to be the minimum value the light sensor would emit. The number max_val I got by pointing a strong light at the sensor, it seems to be the maximum value the sensor emits. The min max values are mixed up because it measures the resistance and decreasing resistance means increasing light intensity. Using this method I get values that are somewhat similar to what I get by connecting the Light unit to PortB directly.
If anyone knows how this should be done properly, please let me know!