PyQGIS2 has a function to expand/collapse a layers with a subset of styles in the Layers panel as follows:
I know that in PyQGIS3
self.iface.legendInterface() has been replaced by
gsProject.instance().layerTreeRoot() but making that switch in this case produces an error:
AttributeError: 'QgsLayerTree' object has no attribute 'setLayerExpanded'
What is the appropriate replacement for
setLayerExpanded in PyQGIS3?